Page 86 - Computational Statistics Handbook with MATLAB
P. 86
72 Computational Statistics Handbook with MATLAB
% Find the median of the upper half - third quartile.
q3 = median(x(51:100));
The quartiles obtained from this random sample are:
q1 = 0.29, q2 = 0.53, q3 = 0.79
The theoretical quartiles for the uniform distribution are q 0.25 = 0.25 ,
q 0.5 = 0.5 , and q 0.75 = 0.75 . So we see that the estimates seem reasonable.
Equation 3.44 provides one way to estimate the quantiles from a random
sample. In some situations, we might need to determine an estimate of a
quantile that does not correspond to j –( 0.5) n . For instance, this is the case
⁄
when we are constructing q-q plots (see Chapter 5), and the sample sizes dif-
fer. We can use interpolation to find estimates of quantiles that are not repre-
sented by Equation 3.44.
Example 3.6
The MATLAB function interp1 (in the standard package) returns the inter-
and
polated value Y I at a given X I , based on some observed values X obs
. The general syntax is
Y obs
yint = interp1(xobs, yobs, xint);
In our case, the argument of F – 1 in Equation 3.44 represents the observed val-
ues X obs , and the order statistics X j() correspond to the Y obs . The MATLAB
code for this procedure is shown below.
% First generate some standard normal data.
x = randn(500,1);
% Now get the order statistics. These will serve
% as the observed values for the ordinate (Y_obs).
xs = sort(x);
% Now get the observed values for the abscissa (X_obs).
n=length(x);
phat = ((1:n)-0.5)/n;
% We want to get the quartiles.
p = [0.25, 0.5, 0.75];
% The following provides the estimates of the quartiles
% using linear interpolation.
qhat = interp1(phat,xs,p);
The resulting estimates are
qhat = -0.6928 0.0574 0.6453.
The reader is asked to explore this further in the exercises.
© 2002 by Chapman & Hall/CRC