how can I Replace outliers with median of previous observations?

1 visualización (últimos 30 días)
Nicolas
Nicolas el 19 de Jul. de 2012
Hello i have some outliers in a 206*174 dataset matrix.. I want to replace them with the median of the 5 previous observaitons using a loop..
how can i do that?
[EDITED, copied from Answer section, Jan]
i will be more clear.. outliers are observations of stationary series with absolute deviations from the median which exceed six times the interquartile range. I want to replace them with the median of the preceding five observations. thanks
  7 comentarios
Nicolas
Nicolas el 19 de Jul. de 2012
So i will repeat.. I have a data of 206*174 observations... rows is time observations and columns is variables.. i want to find the outliers that are defined the the median absolute deviations to be greater 6 times the interquartile range in each variable series.
after that i want to replace each outlier with the median of previous 5 rows. thanks
Nicolas
Nicolas el 19 de Jul. de 2012
% %Now we remove outliers like the paper of Stock and Watson 2005(num=data)
[t n]=size(NUM)% row size of data
X=median(NUM) %find the median of each column of NUM
X1=repmat(X,t,1)% creates a large matrix that
% each column has n times the median value of the column
NUM1=NUM-X1 %substract each row to find the Mean absolute deviation
NUM1=abs(NUM(:,:))%take the absolute value
for j=1:n
Y(:,j)=iqr(NUM(:,j))% find the value of the difference between
%3 and 1 quartile.
end
Y1=repmat(Y,t,1)
NUM2=6*Y1% multiply each value x6
outliers=NUM1-NUM2 %an outlier is when the MAD>6*Diff inquartiles
[x w]=find(outliers>0)%x is the row and w the column of each outlier
v=ones(t,n)
v(outliers>0)=0
%Note here that some problems arise for very smooth series so we remove %them for further analysis v(:,[39;84;86;92;95])=1 [x w]=find(v==0)
NUM1=zeros(size(data_st)) j=1
for i=1:t
if v(i,j)==0
NUM1(i,:)=NUM(median(NUM(i-6:i-1,:),1))
elseif v(i,:)==1
NUM1(i,:)=data_st(i,:)
end
j=j+1
if j==175
break
end
end
disp('Done')

Iniciar sesión para comentar.

Respuestas (1)

Miro
Miro el 19 de Jul. de 2012
Editada: Miro el 19 de Jul. de 2012
something like this should work
yourthreshold = 10;
Data(Data>yourthreshold) = median(median(Data));
this replaces all values being greater than 10.

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by