]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/meandev.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / meandev.m
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)
5 %
6 % y = meandev(x,DIM)
7 %   calculates the mean deviation of x in dimension DIM
8 %
9 % DIM   dimension
10 %       1: STATS of columns
11 %       2: STATS of rows
12 %       default or []: first DIMENSION, with more than 1 element
13 %
14 % features:
15 % - can deal with NaN's (missing values)
16 % - dimension argument 
17 % - compatible to Matlab and Octave
18 %
19 % see also: SUMSKIPNAN, VAR, STD, MAD
20 %
21 % REFERENCE(S):
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. 
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 2 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 %       $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/
44         
45 if nargin==1,
46         DIM = find(size(i)>1,1);
47         if isempty(DIM), DIM=1; end;
48 end;
49
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);         % 
53
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
56 %else
57 %       n1 = N;
58 %end;
59
60 R     = S./n1;
61
62