Mercurial > hg > octave-nkf
annotate scripts/statistics/base/ppplot.m @ 11436:e151e23f73bc
Overhaul base statistics functions and documentation of same.
Add or improve input validation.
Add input validation tests.
Add functional tests.
Improve or re-write documentation strings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 03 Jan 2011 21:23:08 -0800 |
parents | a1dbe9d80eee |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, |
2 ## 2006, 2007 Kurt Hornik | |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
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 | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
3200 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
3200 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3200 | 19 |
3453 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {[@var{p}, @var{y}] =} ppplot (@var{x}, @var{dist}, @var{params}) | |
22 ## Perform a PP-plot (probability plot). | |
3200 | 23 ## |
3453 | 24 ## If F is the CDF of the distribution @var{dist} with parameters |
25 ## @var{params} and @var{x} a sample vector of length @var{n}, the | |
26 ## PP-plot graphs ordinate @var{y}(@var{i}) = F (@var{i}-th largest | |
27 ## element of @var{x}) versus abscissa @var{p}(@var{i}) = (@var{i} - | |
28 ## 0.5)/@var{n}. If the sample comes from F, the pairs will | |
29 ## approximately follow a straight line. | |
3200 | 30 ## |
3453 | 31 ## The default for @var{dist} is the standard normal distribution. The |
32 ## optional argument @var{params} contains a list of parameters of | |
33 ## @var{dist}. For example, for a probability plot of the uniform | |
34 ## distribution on [2,4] and @var{x}, use | |
35 ## | |
36 ## @example | |
37 ## ppplot (x, "uniform", 2, 4) | |
38 ## @end example | |
3200 | 39 ## |
6754 | 40 ## @noindent |
41 ## @var{dist} can be any string for which a function @var{dist_cdf} | |
42 ## that calculates the CDF of distribution @var{dist} exists. | |
43 ## | |
3200 | 44 ## If no output arguments are given, the data are plotted directly. |
3453 | 45 ## @end deftypefn |
3200 | 46 |
5428 | 47 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 48 ## Description: Perform a PP-plot (probability plot) |
3200 | 49 |
3979 | 50 function [p, y] = ppplot (x, dist, varargin) |
3426 | 51 |
3200 | 52 if (nargin < 1) |
6046 | 53 print_usage (); |
3200 | 54 endif |
3426 | 55 |
4030 | 56 if (! isvector (x)) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
57 error ("ppplot: X must be a vector"); |
3200 | 58 endif |
59 | |
60 s = sort (x); | |
61 n = length (x); | |
62 p = ((1 : n)' - 0.5) / n; | |
63 if (nargin == 1) | |
4348 | 64 F = @stdnormal_cdf; |
3200 | 65 else |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
66 F = str2func (sprintf ("%scdf", dist)); |
3200 | 67 endif; |
68 if (nargin <= 2) | |
69 y = feval (F, s); | |
70 else | |
3979 | 71 y = feval (F, s, varargin{:}); |
3200 | 72 endif |
3426 | 73 |
3200 | 74 if (nargout == 0) |
6447 | 75 plot (p, y); |
3200 | 76 axis ([0, 1, 0, 1]); |
77 endif | |
78 | |
79 endfunction | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
80 |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
81 %% Test input validation |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
82 %!error ppplot (); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
83 %!error ppplot (ones(2,2)); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
84 |