1 function R = skewness(i,DIM)
2 % SKEWNESS estimates the skewness
5 % calculates skewness of x in dimension DIM
10 % default or []: first DIMENSION, with more than 1 element
13 % - can deal with NaN's (missing values)
14 % - dimension argument
15 % - compatible to Matlab and Octave
17 % see also: SUMSKIPNAN, STATISTIC
20 % http://mathworld.wolfram.com/
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/
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.
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.
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/>.
42 % check input arguments
45 DIM = find(size(i)>1,1);
46 if isempty(DIM), DIM=1; end;
49 [R.SUM,R.N,R.SSQ] = sumskipnan(i,DIM); % sum
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
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
60 R.VAR = R.SSQ0./n1; % variance (unbiased)
61 R.STD = sqrt(R.VAR); % standard deviation
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;
67 R = R.CM3./(R.STD.^3);
68 %R = R.CM4./(R.VAR.^2)-3;