Mercurial > octave-nkf
annotate scripts/statistics/base/__quantile__.m @ 8664:e07e93c04080
style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 04 Feb 2009 10:56:23 -0500 |
parents | cf59d542f33e |
children | 7d48766c21a5 |
rev | line source |
---|---|
7643
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
1 ## Copyright (C) 2008 Ben Abbott, Jaroslav Hajek |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
2 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
4 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
8 ## your option) any later version. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
9 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
13 ## General Public License for more details. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
14 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
18 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {@var{q} =} __quantile__ (@var{x}, @var{p}) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{q} =} __quantile__ (@var{x}, @var{p}, @var{method}) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
22 ## For the cumulative probability values in @var{p}, compute the |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
23 ## quantiles, @var{q} (the inverse of the cdf), for the sample, @var{x}. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
24 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
25 ## The optional input, @var{method}, refers to nine methods available in R |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
26 ## (http://www.r-project.org/). The default is @var{method} = 7. For more |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
27 ## detail, see `help quantile'. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
28 ## @seealso{prctile, quantile, statistics} |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
29 ## @end deftypefn |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
30 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
31 ## Author: Ben Abbott <bpabbott@mac.com> |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
32 ## Vectorized version: Jaroslav Hajek <highegg@gmail.com> |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
33 ## Description: Quantile function of a empirical samples |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
34 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
35 function inv = __quantile__ (x, p, method = 5) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
36 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
37 if (nargin < 2 || nargin > 3) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
38 print_usage (); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
39 endif |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
40 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
41 if (! ismatrix (x)) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
42 error ("quantile: x must be a matrix"); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
43 endif |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
44 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
45 ## Save length and set shape of quantiles. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
46 n = numel (p); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
47 p = p(:); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
48 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
49 ## Save length and set shape of samples. |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
7643
diff
changeset
|
50 ## FIXME: does sort guarantee that NaN's come at the end? |
7643
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
51 x = sort (x); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
52 m = sum (! isnan (x)); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
53 mx = size (x, 1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
54 nx = size (x, 2); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
55 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
56 ## Initialize output values. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
57 inv = Inf*(-(p < 0) + (p > 1)); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
58 inv = repmat (inv, 1, nx); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
59 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
60 ## Do the work. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
61 if (any(k = find((p >= 0) & (p <= 1)))) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
62 n = length (k); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
63 p = p (k); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
64 ## Special case. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
65 if (mx == 1) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
66 inv(k,:) = repmat (x, n, 1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
67 return |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
68 endif |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
69 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
70 ## The column-distribution indices. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
71 pcd = kron (ones (n, 1), mx*(0:nx-1)); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
72 mm = kron (ones (n, 1), m); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
73 switch method |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
74 case {1, 2, 3} |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
75 switch method |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
76 case 1 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
77 p = max (ceil (kron (p, m)), 1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
78 inv(k,:) = x(p + pcd); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
79 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
80 case 2 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
81 p = kron (p, m); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
82 p_lr = max (ceil (p), 1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
83 p_rl = min (floor (p + 1), mm); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
84 inv(k,:) = (x(p_lr + pcd) + x(p_rl + pcd))/2; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
85 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
86 case 3 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
87 ## Used by SAS, method PCTLDEF=2. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
88 ## http://support.sas.com/onlinedoc/913/getDoc/en/statug.hlp/stdize_sect14.htm |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
89 t = max (kron (p, m), 1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
90 t = roundb (t); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
91 inv(k,:) = x(t + pcd); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
92 endswitch |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
93 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
94 otherwise |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
95 switch method |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
96 case 4 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
97 p = kron (p, m); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
98 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
99 case 5 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
100 ## Used by Matlab. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
101 p = kron (p, m) + 0.5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
102 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
103 case 6 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
104 ## Used by Minitab and SPSS. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
105 p = kron (p, m+1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
106 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
107 case 7 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
108 ## Used by S and R. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
109 p = kron (p, m-1) + 1; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
110 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
111 case 8 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
112 ## Median unbiased . |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
113 p = kron (p, m+1/3) + 1/3; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
114 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
115 case 9 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
116 ## Approximately unbiased respecting order statistics. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
117 p = kron (p, m+0.25) + 0.375; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
118 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
119 otherwise |
8664 | 120 error ("quantile: Unknown method, '%d'", method); |
7643
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
121 endswitch |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
122 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
123 ## Duplicate single values. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
124 imm1 = mm == 1; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
125 x(2,imm1) = x(1,imm1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
126 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
127 ## Interval indices. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
128 pi = max (min (floor (p), mm-1), 1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
129 pr = max (min (p - pi, 1), 0); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
130 pi += pcd; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
131 inv(k,:) = (1-pr) .* x(pi) + pr .* x(pi+1); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
132 endswitch |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
133 endif |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
134 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
135 endfunction |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
136 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
137 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
138 %! p = 0.5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
139 %! x = sort (rand (11)); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
140 %! q = __quantile__ (x, p); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
141 %! assert (q, x(6,:)) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
142 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
143 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
144 %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
145 %! x = [1; 2; 3; 4]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
146 %! a = [1.0000 1.0000 2.0000 3.0000 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
147 %! 1.0000 1.5000 2.5000 3.5000 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
148 %! 1.0000 1.0000 2.0000 3.0000 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
149 %! 1.0000 1.0000 2.0000 3.0000 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
150 %! 1.0000 1.5000 2.5000 3.5000 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
151 %! 1.0000 1.2500 2.5000 3.7500 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
152 %! 1.0000 1.7500 2.5000 3.2500 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
153 %! 1.0000 1.4167 2.5000 3.5833 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
154 %! 1.0000 1.4375 2.5000 3.5625 4.0000]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
155 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
156 %! q = __quantile__ (x, p, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
157 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
158 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
159 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
160 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
161 %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
162 %! x = [1; 2; 3; 4; 5]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
163 %! a = [1.0000 2.0000 3.0000 4.0000 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
164 %! 1.0000 2.0000 3.0000 4.0000 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
165 %! 1.0000 1.0000 2.0000 4.0000 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
166 %! 1.0000 1.2500 2.5000 3.7500 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
167 %! 1.0000 1.7500 3.0000 4.2500 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
168 %! 1.0000 1.5000 3.0000 4.5000 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
169 %! 1.0000 2.0000 3.0000 4.0000 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
170 %! 1.0000 1.6667 3.0000 4.3333 5.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
171 %! 1.0000 1.6875 3.0000 4.3125 5.0000]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
172 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
173 %! q = __quantile__ (x, p, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
174 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
175 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
176 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
177 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
178 %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
179 %! x = [1; 2; 5; 9]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
180 %! a = [1.0000 1.0000 2.0000 5.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
181 %! 1.0000 1.5000 3.5000 7.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
182 %! 1.0000 1.0000 2.0000 5.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
183 %! 1.0000 1.0000 2.0000 5.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
184 %! 1.0000 1.5000 3.5000 7.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
185 %! 1.0000 1.2500 3.5000 8.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
186 %! 1.0000 1.7500 3.5000 6.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
187 %! 1.0000 1.4167 3.5000 7.3333 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
188 %! 1.0000 1.4375 3.5000 7.2500 9.0000]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
189 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
190 %! q = __quantile__ (x, p, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
191 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
192 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
193 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
194 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
195 %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
196 %! x = [1; 2; 5; 9; 11]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
197 %! a = [1.0000 2.0000 5.0000 9.0000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
198 %! 1.0000 2.0000 5.0000 9.0000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
199 %! 1.0000 1.0000 2.0000 9.0000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
200 %! 1.0000 1.2500 3.5000 8.0000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
201 %! 1.0000 1.7500 5.0000 9.5000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
202 %! 1.0000 1.5000 5.0000 10.0000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
203 %! 1.0000 2.0000 5.0000 9.0000 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
204 %! 1.0000 1.6667 5.0000 9.6667 11.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
205 %! 1.0000 1.6875 5.0000 9.6250 11.0000]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
206 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
207 %! q = __quantile__ (x, p, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
208 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
209 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
210 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
211 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
212 %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
213 %! x = [16; 11; 15; 12; 15; 8; 11; 12; 6; 10]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
214 %! a = [6.0000 10.0000 11.0000 15.0000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
215 %! 6.0000 10.0000 11.5000 15.0000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
216 %! 6.0000 8.0000 11.0000 15.0000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
217 %! 6.0000 9.0000 11.0000 13.5000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
218 %! 6.0000 10.0000 11.5000 15.0000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
219 %! 6.0000 9.5000 11.5000 15.0000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
220 %! 6.0000 10.2500 11.5000 14.2500 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
221 %! 6.0000 9.8333 11.5000 15.0000 16.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
222 %! 6.0000 9.8750 11.5000 15.0000 16.0000]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
223 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
224 %! q = __quantile__ (x, p, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
225 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
226 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
227 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
228 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
229 %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
230 %! x = [-0.58851; 0.40048; 0.49527; -2.551500; -0.52057; ... |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
231 %! -0.17841; 0.057322; -0.62523; 0.042906; 0.12337]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
232 %! a = [-2.551474 -0.588505 -0.178409 0.123366 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
233 %! -2.551474 -0.588505 -0.067751 0.123366 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
234 %! -2.551474 -0.625231 -0.178409 0.123366 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
235 %! -2.551474 -0.606868 -0.178409 0.090344 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
236 %! -2.551474 -0.588505 -0.067751 0.123366 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
237 %! -2.551474 -0.597687 -0.067751 0.192645 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
238 %! -2.551474 -0.571522 -0.067751 0.106855 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
239 %! -2.551474 -0.591566 -0.067751 0.146459 0.495271 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
240 %! -2.551474 -0.590801 -0.067751 0.140686 0.495271]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
241 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
242 %! q = __quantile__ (x, p, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
243 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
244 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
245 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
246 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
247 %! p = 0.5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
248 %! x = [0.112600, 0.114800, 0.052100, 0.236400, 0.139300 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
249 %! 0.171800, 0.727300, 0.204100, 0.453100, 0.158500 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
250 %! 0.279500, 0.797800, 0.329600, 0.556700, 0.730700 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
251 %! 0.428800, 0.875300, 0.647700, 0.628700, 0.816500 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
252 %! 0.933100, 0.931200, 0.963500, 0.779600, 0.846100]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
253 %! tol = 0.00001; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
254 %! x(5,5) = NaN; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
255 %! assert (__quantile__ (x, p), [0.27950, 0.79780, 0.32960, 0.55670, 0.44460], tol); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
256 %! x(1,1) = NaN; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
257 %! assert (__quantile__ (x, p), [0.35415, 0.79780, 0.32960, 0.55670, 0.44460], tol); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
258 %! x(3,3) = NaN; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
259 %! assert (__quantile__ (x, p), [0.35415, 0.79780, 0.42590, 0.55670, 0.44460], tol); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
260 |