forked from mwgeurts/libra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadm.m
executable file
·43 lines (38 loc) · 1.18 KB
/
adm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function result = adm(x)
%ADM is a scale estimator given by the Average Distance to the Median.
% It is defined as
% adm(x) = ave(|x_i - med(x)|)
% If x is a matrix, the scale estimate is computed on the columns of x. The
% result is then a row vector. If x is a row or a column vector,
% the output is a scalar.
%
% The ADM is also described in:
% Rousseeuw, P.J. and Verboven, S. (2002),
% "Robust Estimation in Very Small Samples",
% Computational Statistics and Data Analysis, 40, 741-758.
%
% Required input argument:
% x : either a data matrix with n observations in rows, p variables in columns
% or a vector of length n.
%
% I/O: out=adm(x);
%
% This function is part of LIBRA: the Matlab Library for Robust Analysis,
% available at:
% http://wis.kuleuven.be/stat/robust
%
% Written by Sabine Verboven
% Last revision 28/08/03 by Nele Smets
[n,p]=size(x);
if n==1 & p==1
result=0; %if X is of size 1x1, the scale estimate is equal to 0
return
elseif n==1
x=x'; %if X is row vector, transpose to a column vector
n=p;
p=1;
end
for i=1:p
X=x(:,i);
result(i)=mean(abs(X-median(X)));
end