3200
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3200
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
3200
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3200
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3453
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}, @var{params}) |
|
19 ## Perform a QQ-plot (quantile plot). |
3200
|
20 ## |
3453
|
21 ## If F is the CDF of the distribution @var{dist} with parameters |
|
22 ## @var{params} and G its inverse, and @var{x} a sample vector of length |
|
23 ## @var{n}, the QQ-plot graphs ordinate @var{s}(@var{i}) = @var{i}-th |
|
24 ## largest element of x versus abscissa @var{q}(@var{i}f) = G((@var{i} - |
|
25 ## 0.5)/@var{n}). |
3200
|
26 ## |
|
27 ## If the sample comes from F except for a transformation of location |
|
28 ## and scale, the pairs will approximately follow a straight line. |
|
29 ## |
3453
|
30 ## The default for @var{dist} is the standard normal distribution. The |
|
31 ## optional argument @var{params} contains a list of parameters of |
|
32 ## @var{dist}. For example, for a quantile plot of the uniform |
|
33 ## distribution on [2,4] and @var{x}, use |
|
34 ## |
|
35 ## @example |
|
36 ## qqplot (x, "uniform", 2, 4) |
|
37 ## @end example |
3200
|
38 ## |
|
39 ## If no output arguments are given, the data are plotted directly. |
3453
|
40 ## @end deftypefn |
3200
|
41 |
3456
|
42 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
43 ## Description: Perform a QQ-plot (quantile plot) |
3200
|
44 |
|
45 function [q, s] = qqplot (x, dist, ...) |
3426
|
46 |
3200
|
47 if (nargin < 1) |
3456
|
48 usage ("qqplot (x, dist, params)"); |
3200
|
49 endif |
3426
|
50 |
3457
|
51 if (! (is_vector(x))) |
3456
|
52 error ("qqplot: x must be a vector."); |
3200
|
53 endif |
|
54 |
|
55 s = sort (x); |
|
56 n = length (x); |
|
57 t = ((1 : n)' - .5) / n; |
|
58 if (nargin == 1) |
|
59 f = "stdnormal_inv"; |
|
60 else |
|
61 f = sprintf ("%s_inv", dist); |
|
62 endif; |
|
63 if (nargin <= 2) |
|
64 q = feval (f, t); |
|
65 q_label = f; |
|
66 else |
|
67 param_string = sprintf ("%g", va_arg ()); |
|
68 for k = 2 : (nargin - 2); |
|
69 param_string = sprintf ("%s, %g", param_string, va_arg ()) |
|
70 endfor |
|
71 q = eval (sprintf ("%s (t, %s);", f, param_string)); |
|
72 q_label = sprintf ("%s with parameter(s) %s", f, param_string); |
|
73 endif |
3426
|
74 |
3200
|
75 if (nargout == 0) |
|
76 xlabel (q_label); |
|
77 ylabel ("sample points"); |
|
78 set nokey; |
|
79 plot (q, s); |
|
80 endif |
|
81 |
|
82 endfunction |