Mercurial > octave-nkf
annotate scripts/statistics/base/quantile.m @ 7643:0220da981c2a
Modified statistics to calculate consistent median.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Tue, 25 Mar 2008 23:57:49 -0400 |
parents | |
children | bc982528de11 |
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 |
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{dim}) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{q} =} quantile (@var{x}, @var{p}, @var{dim}, @var{method} ) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
23 ## For a sample, @var{x}, calculate the quantiles, @var{q}, corresponding to |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
24 ## the cumulative probability values in @var{p}. All non-numeric values (NaNs) of |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
25 ## @var{x} are ignored. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
26 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
27 ## If @var{x} is a matrix, compute the quantiles for each column and |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
28 ## return them in a matrix, such that the i-th row of @var{q} contains |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
29 ## the @var{p}(i)th quantiles of each column of @var{x}. |
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 ## The optional argument @var{dim} determines the dimension along which |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
32 ## the percentiles are calculated. If @var{dim} is omitted, and @var{x} is |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
33 ## a vector or matrix, it defaults to 1 (column wise quantiles). In the |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
34 ## instance that @var{x} is a N-d array, @var{dim} defaults to the first |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
35 ## dimension whose size greater than unity. |
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 ## The methods available to calculate sample quantiles are the nine methods |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
38 ## used by R (http://www.r-project.org/). The default value is METHOD = 5. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
39 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
40 ## Discontinuous sample quantile methods 1, 2, and 3 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
41 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
42 ## @enumerate 1 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
43 ## @item Method 1: Inverse of empirical distribution function. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
44 ## @item Method 2: Similar to method 1 but with averaging at discontinuities. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
45 ## @item Method 3: SAS definition: nearest even order statistic. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
46 ## @end enumerate |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
47 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
48 ## Continuous sample quantile methods 4 through 9, where p(k) is the linear |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
49 ## interpolation function respecting each methods' representative cdf. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
50 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
51 ## @enumerate 4 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
52 ## @item Method 4: p(k) = k / n. That is, linear interpolation of the empirical cdf. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
53 ## @item Method 5: p(k) = (k - 0.5) / n. That is a piecewise linear function where |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
54 ## the knots are the values midway through the steps of the empirical cdf. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
55 ## @item Method 6: p(k) = k / (n + 1). |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
56 ## @item Method 7: p(k) = (k - 1) / (n - 1). |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
57 ## @item Method 8: p(k) = (k - 1/3) / (n + 1/3). The resulting quantile estimates |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
58 ## are approximately median-unbiased regardless of the distribution of @var{x}. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
59 ## @item Method 9: p(k) = (k - 3/8) / (n + 1/4). The resulting quantile estimates |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
60 ## are approximately unbiased for the expected order statistics if @var{x} is |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
61 ## normally distributed. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
62 ## @end enumerate |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
63 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
64 ## Hyndman and Fan (1996) recommend method 8. Maxima, S, and R |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
65 ## (versions prior to 2.0.0) use 7 as their default. Minitab and SPSS |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
66 ## use method 6. Matlab uses method 5. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
67 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
68 ## References: |
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 ## @itemize @bullet |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
71 ## @item Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
72 ## S Language. Wadsworth & Brooks/Cole. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
73 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
74 ## @item Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
75 ## statistical packages, American Statistician, 50, 361-365. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
76 ## |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
77 ## @item R: A Language and Environment for Statistical Computing; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
78 ## @url{http://cran.r-project.org/doc/manuals/fullrefman.pdf}. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
79 ## @end itemize |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
80 ## @end deftypefn |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
81 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
82 ## Author: Ben Abbott <bpabbott@mac.com> |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
83 ## Description: Matlab style quantile function of a discrete/continuous distribution |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
84 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
85 function q = quantile (x, p, dim, method) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
86 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
87 if (nargin < 1 || nargin > 4) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
88 print_usage (); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
89 endif |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
90 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
91 if (nargin < 2) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
92 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
|
93 endif |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
94 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
95 if (nargin < 3) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
96 dim = 1; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
97 endif |
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 if (nargin < 4) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
100 method = 5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
101 endif |
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 if (dim > ndims(x)) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
104 error ("quantile: invalid dimension.") |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
105 endif |
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 # Set the permutation vector. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
108 perm = 1:ndims(x); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
109 perm(1) = dim; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
110 perm(dim) = 1; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
111 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
112 # Permute dim to the 1st index. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
113 x = permute (x, perm); |
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 # Save the size of the permuted x N-d array. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
116 sx = size (x); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
117 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
118 # Reshape to a 2-d array. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
119 x = reshape (x, [sx(1), prod(sx(2:end))]); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
120 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
121 # Calculate the quantiles. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
122 q = __quantile__ (x, p, method); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
123 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
124 # Return the shape to the original N-d array. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
125 q = reshape (q, [numel(p), sx(2:end)]); |
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 # Permute the 1st index back to dim. |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
128 q = ipermute (q, perm); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
129 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
130 endfunction |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
131 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
132 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
133 %! p = 0.5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
134 %! x = sort (rand (11)); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
135 %! q = quantile (x, p); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
136 %! assert (q, x(6,:)) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
137 %! x = x.'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
138 %! q = quantile (x, p, 2); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
139 %! assert (q, x(:,6)); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
140 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
141 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
142 %! 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
|
143 %! x = [1; 2; 3; 4]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
144 %! 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
|
145 %! 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
|
146 %! 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.0000 2.0000 3.0000 4.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
148 %! 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
|
149 %! 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
|
150 %! 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
|
151 %! 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
|
152 %! 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
|
153 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
154 %! q = quantile (x, p, 1, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
155 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
156 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
157 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
158 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
159 %! 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
|
160 %! x = [1; 2; 3; 4; 5]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
161 %! 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
|
162 %! 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
|
163 %! 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
|
164 %! 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
|
165 %! 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
|
166 %! 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
|
167 %! 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
|
168 %! 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
|
169 %! 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
|
170 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
171 %! q = quantile (x, p, 1, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
172 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
173 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
174 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
175 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
176 %! 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
|
177 %! x = [1; 2; 5; 9]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
178 %! 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
|
179 %! 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
|
180 %! 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.0000 2.0000 5.0000 9.0000 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
182 %! 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
|
183 %! 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
|
184 %! 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
|
185 %! 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
|
186 %! 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
|
187 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
188 %! q = quantile (x, p, 1, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
189 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
190 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
191 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
192 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
193 %! 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
|
194 %! x = [1; 2; 5; 9; 11]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
195 %! 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
|
196 %! 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
|
197 %! 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
|
198 %! 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
|
199 %! 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
|
200 %! 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
|
201 %! 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
|
202 %! 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
|
203 %! 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
|
204 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
205 %! q = quantile (x, p, 1, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
206 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
207 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
208 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
209 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
210 %! 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
|
211 %! 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
|
212 %! 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
|
213 %! 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
|
214 %! 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
|
215 %! 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
|
216 %! 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
|
217 %! 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
|
218 %! 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
|
219 %! 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
|
220 %! 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
|
221 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
222 %! q = quantile (x, p, 1, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
223 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
224 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
225 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
226 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
227 %! 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
|
228 %! 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
|
229 %! -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
|
230 %! 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
|
231 %! -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
|
232 %! -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
|
233 %! -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
|
234 %! -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
|
235 %! -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
|
236 %! -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
|
237 %! -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
|
238 %! -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
|
239 %! for m = (1:9) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
240 %! q = quantile (x, p, 1, m).'; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
241 %! assert (q, a(m,:), 0.0001) |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
242 %! endfor |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
243 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
244 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
245 %! p = 0.5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
246 %! 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
|
247 %! 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
|
248 %! 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
|
249 %! 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
|
250 %! 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
|
251 %! tol = 0.00001; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
252 %! x(5,5) = NaN; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
253 %! assert (quantile(x, p, 1), [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
|
254 %! x(1,1) = NaN; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
255 %! assert (quantile(x, p, 1), [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
|
256 %! x(3,3) = NaN; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
257 %! assert (quantile(x, p, 1), [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
|
258 |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
259 %!test |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
260 %! sx = [2, 3, 4]; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
261 %! x = rand (sx); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
262 %! dim = 2; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
263 %! p = 0.5; |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
264 %! yobs = quantile (x, p, dim); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
265 %! yexp = median (x, dim); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
266 %! assert (yobs, yexp); |
0220da981c2a
Modified statistics to calculate consistent median.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
267 |