1 function R = meandev(i,DIM)
2 % MEANDEV estimates the Mean deviation
3 % (note that according to [1,2] this is the mean deviation;
4 % not the mean absolute deviation)
7 % calculates the mean deviation of x in dimension DIM
12 % default or []: first DIMENSION, with more than 1 element
15 % - can deal with NaN's (missing values)
16 % - dimension argument
17 % - compatible to Matlab and Octave
19 % see also: SUMSKIPNAN, VAR, STD, MAD
22 % [1] http://mathworld.wolfram.com/MeanDeviation.html
23 % [2] L. Sachs, "Applied Statistics: A Handbook of Techniques", Springer-Verlag, 1984, page 253.
24 % [3] http://mathworld.wolfram.com/MeanAbsoluteDeviation.html
25 % [4] Kenney, J. F. and Keeping, E. S. "Mean Absolute Deviation." ยง6.4 in Mathematics of Statistics, Pt. 1, 3rd ed. Princeton, NJ: Van Nostrand, pp. 76-77 1962.
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 2 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/>.
40 % $Id: meandev.m 8223 2011-04-20 09:16:06Z schloegl $
41 % Copyright (C) 2000-2002,2010 by Alois Schloegl <alois.schloegl@gmail.com>
42 % This function is part of the NaN-toolbox for Octave and Matlab
43 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
46 DIM = find(size(i)>1,1);
47 if isempty(DIM), DIM=1; end;
50 [S,N] = sumskipnan(i,DIM); % sum
51 i = i - repmat(S./N,size(i)./size(S)); % remove mean
52 [S,N] = sumskipnan(abs(i),DIM); %
54 %if flag_implicit_unbiased_estim; %% ------- unbiased estimates -----------
55 n1 = max(N-1,0); % in case of n=0 and n=1, the (biased) variance, STD and STE are INF