3200
|
1 ## Copyright (C) 1995, 1996, 1997 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 |
3200
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## 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 |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
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 ## |
|
40 ## If no output arguments are given, the data are plotted directly. |
3453
|
41 ## @end deftypefn |
3200
|
42 |
3456
|
43 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
44 ## Description: Perform a PP-plot (probability plot) |
3200
|
45 |
3979
|
46 function [p, y] = ppplot (x, dist, varargin) |
3426
|
47 |
3200
|
48 if (nargin < 1) |
3456
|
49 usage ("ppplot (x, dist, params)"); |
3200
|
50 endif |
3426
|
51 |
4030
|
52 if (! isvector (x)) |
3458
|
53 error ("ppplot: x must be a vector"); |
3200
|
54 endif |
|
55 |
|
56 s = sort (x); |
|
57 n = length (x); |
|
58 p = ((1 : n)' - 0.5) / n; |
|
59 if (nargin == 1) |
4348
|
60 F = @stdnormal_cdf; |
3200
|
61 else |
4348
|
62 F = str2func (sprintf ("%s_cdf", dist)); |
3200
|
63 endif; |
|
64 if (nargin <= 2) |
|
65 y = feval (F, s); |
|
66 else |
3979
|
67 y = feval (F, s, varargin{:}); |
3200
|
68 endif |
3426
|
69 |
3200
|
70 if (nargout == 0) |
|
71 axis ([0, 1, 0, 1]); |
3787
|
72 gset nokey; |
3200
|
73 plot (p, y); |
|
74 endif |
|
75 |
|
76 endfunction |