how to calculate mean of erased outlier and insert them in their place

1 次查看(过去 30 天)
dear all,
using the code "rmoutlier", i was able to detect outliers as i intended.
But instead of deleting the outlier and thus making the sample size smaller, i was planning to calculate a mean at the location of the outlier using pre- & post-outliers value.
Situation)
I had a value W with idx variables.
Using rmoutlier and 'quartiles', i deleted all the outliers and got a new vector W_rmoutlers (with smaller amout of arrays due to deletion of outliers) and OutlierPosition.
OutlierPosition is another vector product that shows which value within W(idx) were outliers with 1/0. 1 being outlier and 0 being non-outlier.
ex)
[W_rmoutliers,OutlierPosition] = rmoutliers(W(idx),'quartiles')
W_rmoutliers = [2 2 2 2 3 3 3 3 1 1 2 2 5 5 3 3 .................]
OutlierPosition = [0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 0 0 0 1 1 ......................]
searching)
using find code, i was able to locate the position of deleted outlier
OutlierPosition2 = find(OutlierPosition)
OutlierPosition2 = [8 9 14 15 16 .......]
As you may see, there are outliers that have been found in succesive order.
How may i calculte the mean values using pre- & post-OutlierPosition2 value
and place the calculated mean value back in the erased position of the original vector?
Thanks all.
  1 个评论
Tommy
Tommy 2020-4-7
What do you mean by pre- and post- outlier value?
You can get the outliers with
W(OutlierPosition)
and you can find the mean value of these outliers with
mean(W(OutlierPosition))
If you want to replace every outlier in W with this mean value, you can use
W(OutlierPosition) = mean(W(OutlierPosition))

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by