Find, fill, or remove outliers in the Live Editor
The Clean Outlier Data task lets you interactively handle outliers in data. The task automatically generates MATLAB® code for your live script.
Using this task, you can:
Find, fill, or remove outliers from data in a workspace variable.
Customize the methods for finding and filling outliers.
Automatically visualize the outlier data and cleaned data.
To add the Clean Outlier Data task to a live script in the MATLAB Editor:
On the Live Editor tab, select Task > Clean Outlier Data.
In a code block in the script, type a relevant keyword, such as
outlier
or clean
. Select Clean
Outlier Data from the suggested command completions.
Cleaning method
— Cleaning method for filling outliersLinear interpolation
(default) | Constant value
| Center value
| Clip to threshold value
| Previous value
| Next value
| Nearest value
| Spline interpolation
| Shape-preserving cubic interpolation (PCHIP)
| Modified Akima cubic interpolation
| ...Specify the method for filling outliers using one of the following options.
Fill Method | Description |
---|---|
Linear interpolation | Linear interpolation of neighboring, nonoutlier values. |
Constant value | Specified scalar value, which is 0 by default. |
Center value | Center value determined by the find method. |
Clip to threshold value | Fills lower threshold value for elements smaller than the lower threshold determined by the find method. Fills with the upper threshold value for elements larger than the upper threshold determined by the find method. |
Previous value | Previous nonoutlier value. |
Next value | Next nonoutlier value. |
Nearest value | Nearest nonoutlier value. |
Spline interpolation | Piecewise cubic spline interpolation. |
Shape-preserving cubic interpolation
(PCHIP) | Shape-preserving piecewise cubic spline interpolation. |
Modified Akima cubic interpolation | Modified Akima cubic Hermite interpolation. |
Detection method
— Method for detecting outliersMedian
(default) | Mean
| Quartiles
| Grubbs
| Generalized extreme studentized deviate (GESD)
| Moving median
| Moving mean
| Percentiles
| ...Specify the detection method for finding outliers using one of the following options.
Method | Description |
---|---|
Median | Outliers are defined as elements more than the specified threshold of
scaled median absolute deviations (MAD) from the median, which is
3 by default. For input data A , the
scaled MAD is defined as c*median(abs(A-median(A))) , where
c=-1/(sqrt(2)*erfcinv(3/2)) . |
Mean | Outliers are defined as elements more than the specified threshold of
standard deviations from the mean, which is 3 by default.
This method is faster but less robust than
Median . |
Quartiles | Outliers are defined as elements more than the specified threshold of
interquartile ranges above the upper quartile (75 percent) or below the lower
quartile (25 percent), which is 1.5 by default. This method
is useful when the input data is not normally distributed. |
Grubbs | Outliers are detected using Grubbs’s test, which removes one outlier per iteration based on hypothesis testing. This method assumes that the input data is normally distributed. |
Generalized extreme studentized deviate
(GESD) | Outliers are detected using the generalized extreme studentized deviate
test for outliers. This iterative method is similar to
Grubbs , but can perform better when multiple
outliers are masking each other. |
Moving median | Outliers are defined as elements more than the specified threshold of local
scaled MAD from the local median over a specified window. The default threshold
is 3 . |
Moving mean | Outliers are defined as elements more than the specified threshold of local
standard deviations from the local mean over a specified window. The default
threshold is 3 . |
Percentiles | Outliers are defined as elements outside of the percentile range specified
by an upper and lower threshold. The default lower percentile threshold is
10 and the default upper percentile threshold is
90 . Valid threshold values are in the interval
[0,100]. |
Moving window
— Window for moving methodsCentered
(default) | Asymmetric
Specify the window type and size when the method for detecting outliers is
Moving median
or Moving
mean
.
Window | Description |
---|---|
Centered | Specified window length centered about the current point. |
Asymmetric | Specified window containing the number of elements before the current point and the number of elements after the current point. |
Window sizes are relative to the X-axis variable units.