Question & Answer: Finding outliers in a data set Detecting unusual numbers or outliers in a data set is important in many disciplines, because the outliers identify…..

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, is an outlier if where Hx is the data set mean, x is the data set standard deviation, and N is the number of standard deviations deemed significant. Assign outlierData with all values in userData that are numberStdDevs standard deviations from userDatas 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, 1001.

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, is an outlier if where Hx is the data set mean, x is the data set standard deviation, and N is the number of standard deviations deemed significant. Assign outlierData 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, 1001.

Expert Answer

 

Screenshot of the code:

Sample Output:

Code to copy:

%Define the function getOutliers() with parameters userData

%and numberStdDevs.

function outlierData = getOutliers(userData, numberStdDevs)

 

%Create an array of x values of size 5 and initialize

%it wit 0 values.

arr_x_val = zeros(1,5);

%Calculate the mean of the user data given.

U_k = mean(userData);

%Calculate standard deviation of the user data given.

sigma_k = std(userData);

%Create an array to store the outlier data.

outlierData = [];

 

%Traverse the array userData.

for index = 1:length(userData)

 

%Check if the user data – mean is greater than the

%number of standatd deviation into data set

%standard deviation.

if (abs(userData(index)-

U_k)>(numberStdDevs*sigma_k));

 

%Update the value into the array of x values.

arr_x_val(index) = 1;

 

%Update the value into the array outLier data

%with the current user data value.

outlierData = [outlierData userData(index)];

 

%End the if statement.

end

 

%End the for loop.

end

 

%End the function getOutliers().

end

%Code to call the function getOutliers().

outlierData = getOutliers([9, 50, 51, 49, 100], 1)

outlierData = getOutliers([76, 79, 84, 68, 85, 23, 105, 47, 97, 96, 39], 1)

outlierData = getOutliers([76, 79, 84, 68, 85, 23, 105, 47, 97, 96, 39], 0.5)

Still stressed from student homework?
Get quality assistance from academic writers!