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{q}, @var{s}] =} qqplot (@var{x}, @var{dist}, @var{params}) |
|
22 ## Perform a QQ-plot (quantile plot). |
3200
|
23 ## |
3453
|
24 ## If F is the CDF of the distribution @var{dist} with parameters |
|
25 ## @var{params} and G its inverse, and @var{x} a sample vector of length |
|
26 ## @var{n}, the QQ-plot graphs ordinate @var{s}(@var{i}) = @var{i}-th |
|
27 ## largest element of x versus abscissa @var{q}(@var{i}f) = G((@var{i} - |
|
28 ## 0.5)/@var{n}). |
3200
|
29 ## |
|
30 ## If the sample comes from F except for a transformation of location |
|
31 ## and scale, the pairs will approximately follow a straight line. |
|
32 ## |
3453
|
33 ## The default for @var{dist} is the standard normal distribution. The |
|
34 ## optional argument @var{params} contains a list of parameters of |
|
35 ## @var{dist}. For example, for a quantile plot of the uniform |
|
36 ## distribution on [2,4] and @var{x}, use |
|
37 ## |
|
38 ## @example |
|
39 ## qqplot (x, "uniform", 2, 4) |
|
40 ## @end example |
3200
|
41 ## |
|
42 ## If no output arguments are given, the data are plotted directly. |
3453
|
43 ## @end deftypefn |
3200
|
44 |
3456
|
45 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
46 ## Description: Perform a QQ-plot (quantile plot) |
3200
|
47 |
|
48 function [q, s] = qqplot (x, dist, ...) |
3426
|
49 |
3200
|
50 if (nargin < 1) |
3456
|
51 usage ("qqplot (x, dist, params)"); |
3200
|
52 endif |
3426
|
53 |
3457
|
54 if (! (is_vector(x))) |
3458
|
55 error ("qqplot: x must be a vector"); |
3200
|
56 endif |
|
57 |
|
58 s = sort (x); |
|
59 n = length (x); |
|
60 t = ((1 : n)' - .5) / n; |
|
61 if (nargin == 1) |
|
62 f = "stdnormal_inv"; |
|
63 else |
|
64 f = sprintf ("%s_inv", dist); |
|
65 endif; |
|
66 if (nargin <= 2) |
|
67 q = feval (f, t); |
|
68 q_label = f; |
|
69 else |
|
70 param_string = sprintf ("%g", va_arg ()); |
|
71 for k = 2 : (nargin - 2); |
|
72 param_string = sprintf ("%s, %g", param_string, va_arg ()) |
|
73 endfor |
|
74 q = eval (sprintf ("%s (t, %s);", f, param_string)); |
|
75 q_label = sprintf ("%s with parameter(s) %s", f, param_string); |
|
76 endif |
3426
|
77 |
3200
|
78 if (nargout == 0) |
|
79 xlabel (q_label); |
|
80 ylabel ("sample points"); |
3787
|
81 gset nokey; |
3200
|
82 plot (q, s); |
|
83 endif |
|
84 |
|
85 endfunction |