]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/skewness.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / skewness.m
1 function R = skewness(i,DIM)
2 % SKEWNESS estimates the skewness 
3 %
4 % y = skewness(x,DIM)
5 %   calculates skewness of x in dimension DIM
6 %
7 % DIM   dimension
8 %       1: STATS of columns
9 %       2: STATS of rows
10 %       default or []: first DIMENSION, with more than 1 element
11 %
12 % features:
13 % - can deal with NaN's (missing values)
14 % - dimension argument 
15 % - compatible to Matlab and Octave
16 %
17 % see also: SUMSKIPNAN, STATISTIC
18 %
19 % REFERENCE(S):
20 % http://mathworld.wolfram.com/
21
22 %    $Id: skewness.m 8223 2011-04-20 09:16:06Z schloegl $
23 %    Copyright (C) 2000-2003,2010 by Alois Schloegl <alois.schloegl@gmail.com>
24 %    This function is part of the NaN-toolbox
25 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
26
27 %    This program is free software; you can redistribute it and/or modify
28 %    it under the terms of the GNU General Public License as published by
29 %    the Free Software Foundation; either version 3 of the License, or
30 %    (at your option) any later version.
31 %
32 %    This program is distributed in the hope that it will be useful,
33 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
34 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35 %    GNU General Public License for more details.
36 %
37 %    You should have received a copy of the GNU General Public License
38 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
39
40
41
42 % check input arguments 
43
44 if nargin==1,
45         DIM = find(size(i)>1,1);
46         if isempty(DIM), DIM=1; end;
47 end;
48
49 [R.SUM,R.N,R.SSQ] = sumskipnan(i,DIM);  % sum
50
51 R.MEAN  = R.SUM./R.N;                   % mean 
52 R.SSQ0  = R.SSQ - real(R.SUM).*real(R.MEAN) - imag(R.SUM).*imag(R.MEAN); % sum square with mean removed
53
54 %if flag_implicit_unbiased_estim;    %% ------- unbiased estimates ----------- 
55     n1  = max(R.N-1,0);                 % in case of n=0 and n=1, the (biased) variance, STD and SEM are INF
56 %else
57 %    n1 = R.N;
58 %end;
59
60 R.VAR   = R.SSQ0./n1;                   % variance (unbiased) 
61 R.STD   = sqrt(R.VAR);                  % standard deviation
62
63 i       = i - repmat(R.MEAN,size(i)./size(R.MEAN));
64 R.CM3   = sumskipnan(i.^3,DIM)./n1;
65 %R.CM4  = sumskipnan(i.^4,DIM)./n1;
66
67 R = R.CM3./(R.STD.^3);
68 %R = R.CM4./(R.VAR.^2)-3;