1## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005,
2## 2006, 2007, 2009 Kurt Hornik
4## This file is part of Octave.
6## Octave is free software; you can redistribute it and/or modify it
7## under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
21## @deftypefn {Function File} {} iqr (@var{x}, @var{dim})
22## If @var{x} is a vector, return the interquartile range, i.e., the
23## difference between the upper and lower quartile, of the input data.
25## If @var{x} is a matrix, do the above for first non-singleton
26## dimension of @var{x}. If the option @var{dim} argument is given,
27## then operate along this dimension.
30## Author KH <Kurt.Hornik@wu-wien.ac.at>
31## Description: Interquartile range
33function y = iqr (x, dim)
35 if (nargin != 1 && nargin != 2)
43 ## Find the first non-singleton dimension.
45 while (dim < nd + 1 && sz(dim) == 1)
52 if (! (isscalar (dim) && dim == round (dim))
55 error ("iqr: dim must be an integer and valid dimension");
59 ## This code is a bit heavy, but is needed until empirical_inv
60 ## takes other than vector arguments.
64 stride = prod (sz(1:dim-1));
68 while (offset > stride)
72 offset += offset2 * stride * c;
73 rng = [0 : c-1] * stride + offset;
75 y (i) = empirical_inv (3/4, x(rng)) - empirical_inv (1/4, x(rng));