Home > freetb4matlab > statistics > base > quantile.m

quantile

PURPOSE ^

% For a sample, @var{x}, calculate the quantiles, @var{q}, corresponding to

SYNOPSIS ^

function q = quantile (x, p, dim, method)

DESCRIPTION ^

% -*- texinfo -*-
% @deftypefn {Function File} {@var{q} =} quantile (@var{x}, @var{p})
% @deftypefnx {Function File} {@var{q} =} quantile (@var{x}, @var{p}, @var{dim})
% @deftypefnx {Function File} {@var{q} =} quantile (@var{x}, @var{p}, @var{dim}, @var{method})
% For a sample, @var{x}, calculate the quantiles, @var{q}, corresponding to
% the cumulative probability values in @var{p}.  All non-numeric values (NaNs) of
% @var{x} are ignored.
%
% If @var{x} is a matrix, compute the quantiles for each column and
% return them in a matrix, such that the i-th row of @var{q} contains
% the @var{p}(i)th quantiles of each column of @var{x}.
% 
% The optional argument @var{dim} determines the dimension along which 
% the percentiles are calculated.  If @var{dim} is omitted, and @var{x} is
% a vector or matrix, it defaults to 1 (column wise quantiles).  In the 
% instance that @var{x} is a N-d array, @var{dim} defaults to the first 
% dimension whose size greater than unity.
% 
% The methods available to calculate sample quantiles are the nine methods
% used by R (http://www.r-project.org/).  The default value is METHOD = 5.
% 
% Discontinuous sample quantile methods 1, 2, and 3
% 
% @enumerate 1
% @item Method 1: Inverse of empirical distribution function.
% @item Method 2: Similar to method 1 but with averaging at discontinuities.
% @item Method 3: SAS definition: nearest even order statistic.
% @end enumerate
% 
% Continuous sample quantile methods 4 through 9, where p(k) is the linear
% interpolation function respecting each methods' representative cdf.
% 
% @enumerate 4
% @item Method 4: p(k) = k / n. That is, linear interpolation of the empirical cdf.
% @item Method 5: p(k) = (k - 0.5) / n. That is a piecewise linear function where 
% the knots are the values midway through the steps of the empirical cdf. 
% @item Method 6: p(k) = k / (n + 1).
% @item Method 7: p(k) = (k - 1) / (n - 1).
% @item Method 8: p(k) = (k - 1/3) / (n + 1/3).  The resulting quantile estimates 
% are approximately median-unbiased regardless of the distribution of @var{x}.
% @item Method 9: p(k) = (k - 3/8) / (n + 1/4).  The resulting quantile estimates 
% are approximately unbiased for the expected order statistics if @var{x} is 
% normally distributed.
% @end enumerate
% 
% Hyndman and Fan (1996) recommend method 8.  Maxima, S, and R
% (versions prior to 2.0.0) use 7 as their default.  Minitab and SPSS
% use method 6.  @sc{matlab} uses method 5.
% 
% References:
% 
% @itemize @bullet
% @item Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New
% S Language.  Wadsworth & Brooks/Cole.
%
% @item Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in
% statistical packages, American Statistician, 50, 361--365.
%
% @item R: A Language and Environment for Statistical Computing;
% @url{http://cran.r-project.org/doc/manuals/fullrefman.pdf}.
% @end itemize
% @end deftypefn

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated on Fri 22-May-2009 15:13:00 by m2html © 2003