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)) |
3458
|
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 |
4348
|
66 F = str2func (sprintf ("%s_cdf", 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 |