Limit the effects of extreme data observations

2 ビュー (過去 30 日間)
Pawel Kaszynski
Pawel Kaszynski 2022 年 2 月 28 日
回答済み: Paras Gupta 2023 年 11 月 17 日
How to limit the effects of extreme data observations, and set any z-score less than -3 to -3, and any z-score greater than +3 to +3.

回答 (1 件)

Paras Gupta
Paras Gupta 2023 年 11 月 17 日
Hi Pawel,
I understand that you want to limit the effects of extreme data observations using z-scores.
Setting the z-scores less than -3 to -3 and z-scores greater than +3 to +3, we can limit the effects of extreme observations and obtain corresponding adjusted data points that are within the desired range. The following MATLAB code shows how to do the same:
clear;
clc;
% Example dataset
data = [10, 12, 15, 20, 25, 35, 40, 41, 42, 44, 500];
% Calculate mean and standard deviation
meanValue = mean(data);
stdValue = std(data);
% Compute z-scores
zScores = (data - meanValue) / stdValue
zScores = 1×11
-0.4292 -0.4152 -0.3942 -0.3591 -0.3241 -0.2541 -0.2190 -0.2120 -0.2050 -0.1910 3.0030
% Limit extreme z-scores
zScores(zScores < -3) = -3;
zScores(zScores > 3) = 3;
% Apply adjusted z-scores to original data points
adjustedData = meanValue + zScores * stdValue
adjustedData = 1×11
10.0000 12.0000 15.0000 20.0000 25.0000 35.0000 40.0000 41.0000 42.0000 44.0000 499.5716
You can also refer to the following documentation on 'Standardized z-scores' to make use of the inbuilt 'zscore' function.
Hope this helps.

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by