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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) 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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3200
|
18 |
3453
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} statistics (@var{x}) |
|
21 ## If @var{x} is a matrix, return a matrix with the minimum, first |
|
22 ## quartile, median, third quartile, maximum, mean, standard deviation, |
|
23 ## skewness and kurtosis of the columns of @var{x} as its rows. |
3200
|
24 ## |
3453
|
25 ## If @var{x} is a vector, treat it as a column vector. |
|
26 ## @end deftypefn |
3426
|
27 |
5428
|
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456
|
29 ## Description: Compute basic statistics |
3200
|
30 |
4885
|
31 function S = statistics (X, dim) |
3426
|
32 |
4885
|
33 if (nargin != 1 && nargin != 2) |
6046
|
34 print_usage (); |
3200
|
35 endif |
|
36 |
4885
|
37 nd = ndims (X); |
|
38 sz = size (X); |
|
39 nel = numel (X); |
|
40 if (nargin != 2) |
4886
|
41 ## Find the first non-singleton dimension. |
4885
|
42 dim = 1; |
4886
|
43 while (dim < nd + 1 && sz(dim) == 1) |
4885
|
44 dim = dim + 1; |
|
45 endwhile |
|
46 if (dim > nd) |
|
47 dim = 1; |
|
48 endif |
|
49 else |
4886
|
50 if (! (isscalar (dim) && dim == round (dim)) |
|
51 && dim > 0 |
|
52 && dim < (nd + 1)) |
4885
|
53 error ("statistics: dim must be an integer and valid dimension"); |
3200
|
54 endif |
4885
|
55 endif |
|
56 |
4886
|
57 if (! ismatrix (X) || sz(dim) < 2) |
3456
|
58 error ("statistics: invalid argument"); |
4885
|
59 endif |
|
60 |
|
61 ## This code is a bit heavy, but is needed until empirical_inv |
|
62 ## takes other than vector arguments. |
4886
|
63 c = sz(dim); |
|
64 stride = prod (sz(1:dim-1)); |
|
65 sz(dim) = 3; |
4885
|
66 emp_inv = zeros (sz); |
|
67 for i = 1 : nel / c; |
|
68 offset = i; |
|
69 offset2 = 0; |
|
70 while (offset > stride) |
|
71 offset -= stride; |
|
72 offset2++; |
|
73 endwhile |
|
74 rng = [0 : c-1] * stride + offset + offset2 * stride * c; |
|
75 rng2 = [0 : 2] * stride + offset + offset2 * stride * 3; |
|
76 emp_inv(rng2) = empirical_inv ([0.25; 0.5; 0.75], X(rng)); |
|
77 endfor |
|
78 |
|
79 S = cat (dim, min (X, [], dim), emp_inv, max (X, [], dim), mean (X, dim), |
|
80 std (X, [], dim), skewness (X, dim), kurtosis (X, dim)); |
3426
|
81 |
3200
|
82 endfunction |