Limit the effects of extreme data observations

2 Ansichten (letzte 30 Tage)
Pawel Kaszynski
Pawel Kaszynski am 28 Feb. 2022
Beantwortet: Paras Gupta am 17 Nov. 2023
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.

Antworten (1)

Paras Gupta
Paras Gupta am 17 Nov. 2023
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.

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by