How could i create a function that winsorize and truncate data?
Show older comments
So we want to create a function where we can apply another function "foo" to an array "x" while specifying outliers quantiles. The outliers must be defined by a vector of length 2 where the first entry is the left truncation/winsorization quantile, and the second entry -- the right tail truncation/winsorization quantile
The function must return 3 value; - winsorized ; a function "foo" that has been applied to a winsorized vector "x" - trimmed ; a function "foo" that has been applied to a trimmed vector "x" - base ; a function "foo" that has been applied to a vector "x"
We defined truncation as removing outlier observations We defined winsorization as replacing outlier observations with some appropriate threshold value
The code below is what i already did for the moment but it's not working. The error message is "input argument'outliersQuantiles' might be unused" and they also say that "an indexing expression on the left side of an assignment must have at least one subscript".
***********CODE**********************************
function [ winsorized, trimmed, base] = trimmedStat(x, foo, outlierQuantiles)
%UNTITLED Summary of this function goes here % Detailed explanation goes here
outlierQuantiles = [a, b]; x = x(~isnan(x));
trimmed = foo(x(x >((outlierQuantiles(1)/100)*x) & x <((outlierQuantiles(2)/100)*x)));
base = foo(x);
winsorized = foo(winsorizing(x, (outlierQuantiles(2)-outlierQuantiles(1))));
end
**********
Any advice would be appreciated :)
Answers (0)
Categories
Find more on Descriptive Statistics 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!