How to show 95% quanile in a Boxplot ?

조회 수: 31 (최근 30일)
Karl-Martin
Karl-Martin 2015년 1월 24일
댓글: dpb 2019년 10월 10일
Hi,
I want to compare the forecast performance of Value at Risk (VaR) from two different models by using a boxplot. Put differently the two models estimate the 95% quantile of the Loss distribution. When I try:
q = quantile(Loss,0.95)
boxplot(Data,'labels',{'VaR GARCH','VaR GJR','Loss'})
line([0 7],[q q])
I get:
Where the solid blue line represents the 95% quantile of the Loss distribution. Unfortunately the whiskers do not represent the 5% and 95% quantiles. The whiskers extend to the most extreme data points not considered outliers, and outliers are plotted individually.
How can I force the whiskers to represent the 5% and 95% quantile?
When I try:
q = quantile(Loss,0.95)
boxplot(Data,'whisker',q,'labels',{'VaR GARCH','VaR GJR','Loss'})
line([0 4],[q q])
I get:
Now the whiskers are too far apart from the solid blue line...
Using MATLAB R2014a, Statistics Toolbox 9.0
Thanks in Advance!

채택된 답변

dpb
dpb 2015년 1월 24일
By the TMW definition of the 'whisker' parameter, their extent is based on the assumption of normality and are computed as q3 +/- w(q3 – q1) where q1 and q3 are the 25th and 75th percentiles, respectively. Since
>> q3=norminv(.75)
q3 =
0.6745
we can verify the claim of +/-2.7σ as
>> q3+1.5*(2*q3)
ans =
2.6980
since we know the normal is symmetric. That does, indeed, check...
OK, so now what value for the multiplier do we need for 95%???
>> q95=norminv(0.95)
ans =
1.6449
(look familiar??? :) )
So, working backwards,
>> w95=(q95-q3)/(2*q3)
w95 =
0.7193
Just for sanity check,
>> q3+w95*(2*q3)
ans =
1.6449
>>
Voila!!!
So, try
'whiskers',w95
and see if joy ensues...
  댓글 수: 3
Simona Pernischova
Simona Pernischova 2019년 10월 10일
I have a follow up question:
Now you use the "Loss" Data to get the whiskers adjusted.
But how do you make separate whisker adjustment for each boxplot?
dpb
dpb 2019년 10월 10일
"how do you make separate whisker adjustment for each boxplot?"
I'll presume by "each boxplot" you mean each variable/group. Can't do that directly; you would have to boxplot() each separately using hold on after the first to add subsequent data to the existing axis. I've not messed around with boxplot() enough to know about what you'll run into with trying to create that effect with the problem of having the multiple x positions not overlay one another.
The "tried and true" way to deal with that issue is generally to create dummy data arrays with NaN values for the locations not to be displayed for each case--presume will behave similarly here as does bar for example.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by