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