Limit the effects of extreme data observations
Show older comments
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.
Answers (1)
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
% Limit extreme z-scores
zScores(zScores < -3) = -3;
zScores(zScores > 3) = 3;
% Apply adjusted z-scores to original data points
adjustedData = meanValue + zScores * stdValue
You can also refer to the following documentation on 'Standardized z-scores' to make use of the inbuilt 'zscore' function.
Hope this helps.
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!