How to show 95% quanile in a Boxplot ?

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

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

Thanks for this competitive answer! (The value looks indeed familiar :) )
Because my loss distribution is of course not normal, I applied your procedure to my Loss distribution:
% get quantiles for the Boxplot
q95=quantile(Loss,0.95)
q75=quantile(Loss,0.75)
q25=quantile(Loss,0.25)
% datapoint considered as an outlier if it is larger than
q75 + w(q75 - q25)
I want this to be equal to the 95% quantile:
q75 + w95(q75 - q25) = q95
Now rearrange the equation to get w95:
w95=(q95-q75)/(q75-q25)
w95 =
1.7423
boxplot(Data,'whisker',w95,'labels',{'VaR GARCH','VaR GJR','Loss'})
line([0 4],[q95 q95])
Gives me this:
Now the upper whisker matches exactly the 95% quantile of the Loss distribution (the solid blue line)
Thanks a Lot !
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?
"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)

Asked:

on 24 Jan 2015

Commented:

dpb
on 10 Oct 2019

Community Treasure Hunt

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

Start Hunting!