Be the first to rate this file! 8 Downloads (last 30 days) File Size: 2.81 KB File ID: #22526

Box Plot with Whiskers Plotted at Fixed Percentiles

by Robert

 

24 Dec 2008 (Updated 19 May 2009)

This script uses boxplot but plots the whiskers for a specified percentile.

| Watch this File

File Information
Description

Normally boxplot plots the whiskers with a maximum length based on the distance between the 25th and 75th percentile. This script uses boxplot but plots the whiskers for a specified percentile and only plots the outliers beyond the new whiskers.

Note that the percentile is defined as the data point just beyond the calculated percentile. For example, if the 98th percentile lies between the 4th and 5th highest data points, then the 4th highest data point will be considered the 98th percentile, the whisker will extend to the 4th highest, and only the 4 highest values will be plotted as outliers.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Quartile & Percentile Calculation

Required Products Statistics Toolbox
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
06 May 2009 Peter

unfortunately function doesn't work for me. Seems to include non defined functions as 'nanfree',...

25 Jun 2010 Stephen

This is a useful program.

I found that boxplot_percentwhisk does not handle negative-valued outliers correctly; all negative outliers are automatically cut off.

I removed the code from lines 91 - 94:
    outliers = get(OUT(length(group_list)-i+1),'ydata');
    outlier_index = find(outliers == data_highpercent(i));
    outliers(1:outlier_index) = data_highpercent(i);
    set(OUT(length(group_list)-i+1),'ydata',outliers);

and replaced it with the following code to fix the problem:
    outliers_y = get(OUT(length(group_list)-i+1),'ydata', 'xdata');
    outliers_x = get(OUT(length(group_list)-i+1),'xdata');
    new_outlier_index = ((outliers_y < data_lowpercent(i)) | (outliers_y > data_highpercent(i)));
    outliers_y = outliers_y(new_outlier_index); % Find the outliers that
    outliers_x = outliers_x(new_outlier_index);
    set(OUT(length(group_list)-i+1),'ydata',outliers_y, 'xdata',outliers_x);

25 Jun 2010 Stephen

Sorry, my bug fix included an error.

Lines 91 - 94 in boxplot_percentwhisk should be removed
    outliers = get(OUT(length(group_list)-i+1),'ydata');
    outlier_index = find(outliers == data_highpercent(i));
    outliers(1:outlier_index) = data_highpercent(i);
    set(OUT(length(group_list)-i+1),'ydata',outliers);

Those lines should be replaced with (corrected version):
    outliers_y = get(OUT(length(group_list)-i+1),'ydata');
    outliers_x = get(OUT(length(group_list)-i+1),'xdata');
    new_outlier_index = ((outliers_y < data_lowpercent(i)) | (outliers_y > data_highpercent(i)));
    outliers_y = outliers_y(new_outlier_index);
    outliers_x = outliers_x(new_outlier_index);
    set(OUT(length(group_list)-i+1),'ydata',outliers_y, 'xdata',outliers_x);

Please login to add a comment or rating.
Updates
19 May 2009

Thanks, Peter, for pointing out the dependence on nanfree. I have added that function to the file. Also note that you need the statistics toolbox to access "boxplot"

Tag Activity for this File
Tag Applied By Date/Time
probability Cristina McIntire 29 Dec 2008 13:50:39
data exploration Robert 29 Dec 2008 13:50:58
statistics Robert 29 Dec 2008 13:50:58
earth science Robert 29 Dec 2008 13:50:58
measurement Robert 29 Dec 2008 13:50:58

Contact us at files@mathworks.com