1 function Z = zScoreMedian(X, DIM)
2 % zScoreMedian removes the median and standardizes by the 1.483*median absolute deviation
4 % Usage: Z = zScoreMedian(X, DIM)
6 % DIM: dimension along which z-score should be calculated (1=columns, 2=rows)
7 % (optional, default=first dimension with more than 1 element
10 % Copyright (C) 2003 Patrick Houweling
11 % Copyright (C) 2009 Alois Schloegl
12 % $Id: zScoreMedian.m 8075 2011-01-27 17:10:36Z schloegl $
13 % This function is part of the NaN-toolbox
14 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
16 % This program is free software: you can redistribute it and/or modify
17 % it under the terms of the GNU General Public License as published by
18 % the Free Software Foundation, either version 3 of the License, or
19 % (at your option) any later version.
21 % This program is distributed in the hope that it will be useful,
22 % but WITHOUT ANY WARRANTY; without even the implied warranty of
23 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 % GNU General Public License for more details.
26 % You should have received a copy of the GNU General Public License
27 % along with this program. If not, see <http://www.gnu.org/licenses/>.
35 % robust moment estimators:
37 % - standard deviation: 1.483 * median absolute deviation (medAbsDev);
38 % the factor 1.483 is the ratio of the standard deviation of a normal random variable to its MAD.
40 [D, M] = medAbsDev(X);
42 [D, M] = medAbsDev(X, DIM);
45 % z-score: subtract M and divide by 1.483*D
46 Z = (X - repmat(M, size(X)./size(M))) ./ repmat(1.483*D, size(X)./size(D));