Mercurial > hg > octave-lyh
annotate scripts/statistics/base/qqplot.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | e151e23f73bc |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3200 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3200 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3200 | 18 |
3453 | 19 ## -*- texinfo -*- |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}, @var{params}) |
3453 | 23 ## Perform a QQ-plot (quantile plot). |
3200 | 24 ## |
3453 | 25 ## If F is the CDF of the distribution @var{dist} with parameters |
26 ## @var{params} and G its inverse, and @var{x} a sample vector of length | |
27 ## @var{n}, the QQ-plot graphs ordinate @var{s}(@var{i}) = @var{i}-th | |
28 ## largest element of x versus abscissa @var{q}(@var{i}f) = G((@var{i} - | |
29 ## 0.5)/@var{n}). | |
3200 | 30 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
31 ## If the sample comes from F, except for a transformation of location |
3200 | 32 ## and scale, the pairs will approximately follow a straight line. |
33 ## | |
3453 | 34 ## The default for @var{dist} is the standard normal distribution. The |
35 ## optional argument @var{params} contains a list of parameters of | |
36 ## @var{dist}. For example, for a quantile plot of the uniform | |
37 ## distribution on [2,4] and @var{x}, use | |
38 ## | |
39 ## @example | |
40 ## qqplot (x, "uniform", 2, 4) | |
41 ## @end example | |
3200 | 42 ## |
6754 | 43 ## @noindent |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
44 ## @var{dist} can be any string for which a function @var{distinv} or |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
45 ## @var{dist_inv} exists that calculates the inverse CDF of distribution |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
46 ## @var{dist}. |
6754 | 47 ## |
3200 | 48 ## If no output arguments are given, the data are plotted directly. |
3453 | 49 ## @end deftypefn |
3200 | 50 |
5428 | 51 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 52 ## Description: Perform a QQ-plot (quantile plot) |
3200 | 53 |
3979 | 54 function [q, s] = qqplot (x, dist, varargin) |
3426 | 55 |
3200 | 56 if (nargin < 1) |
6046 | 57 print_usage (); |
3200 | 58 endif |
3426 | 59 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
60 if (!(isnumeric (x) && isvector(x))) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
61 error ("qqplot: X must be a numeric vector"); |
3200 | 62 endif |
63 | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
64 if (nargin == 1) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
65 f = @stdnormal_inv; |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
66 else |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
67 if ( exist (invname = sprintf ("%sinv", dist)) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
68 || exist (invname = sprintf ("%s_inv", dist))) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
69 f = str2func (invname); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
70 else |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
71 error ("qqplot: no inverse CDF found for distribution DIST"); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
72 endif |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
73 endif; |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
74 |
3200 | 75 s = sort (x); |
76 n = length (x); | |
77 t = ((1 : n)' - .5) / n; | |
78 if (nargin <= 2) | |
79 q = feval (f, t); | |
4348 | 80 q_label = func2str (f); |
3200 | 81 else |
5153 | 82 q = feval (f, t, varargin{:}); |
83 if (nargin > 3) | |
84 tmp = sprintf (", %g", varargin{2:end}); | |
85 else | |
86 tmp = ""; | |
87 endif | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
88 q_label = sprintf ("%s with parameter(s) %g%s", |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
89 func2str (f), varargin{1}, tmp); |
3200 | 90 endif |
3426 | 91 |
3200 | 92 if (nargout == 0) |
6447 | 93 plot (q, s); |
3200 | 94 xlabel (q_label); |
95 ylabel ("sample points"); | |
96 endif | |
97 | |
98 endfunction |