zyBooks My library>1AM 550 home> 4.7: Statistics E zyBooks catalog Help/FAO Find
ID: 3371230 • Letter: Z
Question
zyBooks My library>1AM 550 home> 4.7: Statistics E zyBooks catalog Help/FAO Finding outliers in a data set. Detecting unusual numbers or outliers in a data set is important in many disciplines, because the outliers identify interesting phenomena, extreme events, or invalid experimental results. A simple method to check if a data value is an outlier is to see if the value is a significant number of standard deviations away from the mean of the data set. For example, X* is an outlier i where x is the data set mean, Ox is the data set standard deviation, and N is the number of standard deviations deemed significant Assign outierData with all values in userData that are numberStdDevs standard deviations from userData's mean. Hint: use logical indexing to return the outlier data values Ex: If userData is [9, 50, 51, 49, 100 ] and numberStdDevs is 1, then outlierData is (9. 100 Your Function Sa " C Reset MATLAB Documentation 1 function outlierData - getoutliers(userData, numberStdDevs) 21% getoti iers: Return ali elements of input array data that are more than 31% nunstdDevs standard deviations away from the mean. sl % x Inputs: userData array of input data values Inputs: numberStdDevs threshold number of standard deviations to determine whether a particular data value is an outlier 71 % 8% Type here to searchExplanation / Answer
MATLAB CODE:
function outlierData = getOutliers(userData,numberStdDevs)
%getOutliers: Return all elements of input array data that
% are more than numberStdDevs standard deviations away from the mean.
%
% Inputs: userData- array of input data values
% numberStdDevs - threshold number of standard deviations to
% determine whether a particular data value is an outlier.
%
%
MeanUserData = mean(userData); %Calculate Mean of the input data array
StdDevsUserData = std(userData); %Calculate Standard deviation of the input data array
DiffMean = abs(userData - MeanUserData); %Subtract each data value with mean and save the abs value of the difference
outlierData = userData(DiffMean > numberStdDevs*StdDevsUserData); % Check if |X-mean(X)| > N*std Using logical indexing of matlab
end
RESULT:
>> getOutliers([9,50,51,49,100],1)
ans =
9 100
>> getOutliers([76,79,84,68,85,23,105,47,97,96,39],1)
ans =
23 105 39
>> getOutliers([76,79,84,68,85,23,105,47,97,96,39],0.5)
ans =
23 105 47 97 96 39
>> getOutliers([76,79,84,68,85,23,105,47,97,96,39],1.5)
ans =
23
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.