How to show 95% quanile in a Boxplot ?

32 views (last 30 days)
Karl-Martin
Karl-Martin on 24 Jan 2015
Commented: dpb on 10 Oct 2019
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!

Accepted Answer

dpb
dpb on 24 Jan 2015
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 Comments
Simona Pernischova
Simona Pernischova on 10 Oct 2019
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 on 10 Oct 2019
"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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!