1 ## Copyright (C) 1995-2012 Kurt Hornik
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x})
21 ## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist})
22 ## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}, @var{params})
23 ## @deftypefnx {Function File} {} qqplot (@dots{})
24 ## Perform a QQ-plot (quantile plot).
26 ## If F is the CDF of the distribution @var{dist} with parameters
27 ## @var{params} and G its inverse, and @var{x} a sample vector of length
28 ## @var{n}, the QQ-plot graphs ordinate @var{s}(@var{i}) = @var{i}-th
29 ## largest element of x versus abscissa @var{q}(@var{i}f) = G((@var{i} -
32 ## If the sample comes from F, except for a transformation of location
33 ## and scale, the pairs will approximately follow a straight line.
35 ## The default for @var{dist} is the standard normal distribution. The
36 ## optional argument @var{params} contains a list of parameters of
37 ## @var{dist}. For example, for a quantile plot of the uniform
38 ## distribution on [2,4] and @var{x}, use
41 ## qqplot (x, "unif", 2, 4)
45 ## @var{dist} can be any string for which a function @var{distinv} or
46 ## @var{dist_inv} exists that calculates the inverse CDF of distribution
49 ## If no output arguments are given, the data are plotted directly.
52 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
53 ## Description: Perform a QQ-plot (quantile plot)
55 function [q, s] = qqplot (x, dist, varargin)
61 if (!(isnumeric (x) && isvector(x)))
62 error ("qqplot: X must be a numeric vector");
68 if ( exist (invname = sprintf ("%sinv", dist))
69 || exist (invname = sprintf ("%s_inv", dist)))
70 f = str2func (invname);
72 error ("qqplot: no inverse CDF found for distribution DIST");
78 t = ((1 : n)' - .5) / n;
81 q_label = func2str (f);
83 q = feval (f, t, varargin{:});
85 tmp = sprintf (", %g", varargin{2:end});
89 q_label = sprintf ("%s with parameter(s) %g%s",
90 func2str (f), varargin{1}, tmp);
96 ylabel ("sample points");