Home > wafo > wstats > iqr.m

iqr

PURPOSE ^

Computes the Inter Quartile Range

SYNOPSIS ^

r = iqr(X,dim)

DESCRIPTION ^

 IQR Computes the Inter Quartile Range
 
  CALL:  r = iqr(X,dim);
 
         r = abs(diff(wquantile(X,[0.25 .75]))),
         X = data vector or matrix
       dim = dimension to sum across. (default 1'st non-singleton 
                                               dimension of X)
  IQR is a robust measure of spread.
  The use of interquartile range guards against outliers if 
  the distribution have heavy tails.
 
  Example:
    R=wgumbrnd(2,2,[],100,2);
    iqr(R)
 
  See also  std

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function r = iqr(X,dim)
002 %IQR Computes the Inter Quartile Range
003 %
004 % CALL:  r = iqr(X,dim);
005 %
006 %        r = abs(diff(wquantile(X,[0.25 .75]))),
007 %        X = data vector or matrix
008 %      dim = dimension to sum across. (default 1'st non-singleton 
009 %                                              dimension of X)
010 % IQR is a robust measure of spread.
011 % The use of interquartile range guards against outliers if 
012 % the distribution have heavy tails.
013 %
014 % Example:
015 %   R=wgumbrnd(2,2,[],100,2);
016 %   iqr(R)
017 %
018 % See also  std
019 
020 % Tested on: Matlab 5.3
021 % History:
022 % revised pab 24.10.2000
023 
024 error(nargchk(1,2,nargin))
025 sz = size(X);
026 if nargin<2|isempty(dim),
027   % Use 1'st non-singleton dimension or dimension 1
028   dim = min(find(sz~=1)); 
029   if isempty(dim), dim = 1; end
030 end
031 
032 if dim~=1, 
033   iorder=1:length(sz);
034   tmp=iorder(dim);
035   iorder(dim)=iorder(1);
036   iorder(1)=tmp;
037   X = permute(X,iorder);
038 end
039 r = abs(diff(wquantile(X,[0.25 0.75])));
040 
041 if dim~=1, 
042   iorder=1:length(sz);
043   tmp=iorder(dim);
044   iorder(dim)=iorder(1);
045   iorder(1)=tmp;
046   r=ipermute(r,iorder);
047 end
048 
049 
050 %sz(dim)=sz(dim);
051 
052 
053 
054

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003