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

조회 수: 1 (최근 30일)
Sehoon Chang
Sehoon Chang 2020년 4월 6일
댓글: Tommy 2020년 4월 7일
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