smoothmedian (x, dim, Tol)

version 1.8.1.1 (294 KB) by Andrew Penn
A smooth version of the median

197 Downloads

Updated Sun, 23 Oct 2022 22:04:59 +0000

View License

[M] = smoothmedian (x)
[M] = smoothmedian (x, dim)
[M] = smoothmedian (x, dim, Tol)
If x is a vector, find the univariate smoothed median (M) of x.
If x is a matrix, compute the univariate smoothed median value for each column and return them in a row vector. If the optional argument dim is given, operate along this dimension. Arrays of more than two dimensions are not currently supported. Data (x) values that are equal to NaN are ignored.
The smoothed median is a slightly smoothed version of the ordinary median and is an M-estimator that is both robust and efficient, where it's breakdown point, and efficiency relative to the mean, are 0.341 amd 0.865 respectively.
Smoothing the median is achieved by minimizing the following objective function:
S (M) = sum ((x(i) - M).^2 + (x(j) - M).^2) .^ 0.5
i < j
where i and j refers to the indices of the Cartesian product of each column of x with itself.
With the ordinary median as the initial value of M, this function minimizes the above objective function by finding the root of the first derivative using a fast, but reliable, Newton-Bisection hybrid algorithm. The tolerance (Tol) is the maximum value of the first derivative that is acceptable to break from optimization. The default value of Tol is 1e-03.
The smoothing works by slightly reducing the breakdown point of the median. Bootstrap confidence intervals using the smoothed median have good coverage for the ordinary median of the population distribution and can be used to obtain second order accurate intervals with Studentized bootstrap and calibrated percentile bootstrap methods [1]. When the population distribution is thought to be strongly skewed, coverage errors can be reduced by improving symmetry through appropriate data transformation. Unlike kernel-based smoothing approaches, bootstrapping smoothmedian does not require explicit choice of a smoothing parameter or a probability density function.
This function is already included in the statistics-bootstrap package (https://uk.mathworks.com/matlabcentral/fileexchange/52741-statistics-bootstrap).
Bibliography:
[1] Brown, Hall and Young (2001) The smoothed median and the bootstrap. Biometrika 88(2):519-534

Cite As

Andrew Penn (2022). smoothmedian (x, dim, Tol) (https://www.mathworks.com/matlabcentral/fileexchange/52737-smoothmedian-x-dim-tol), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022a
Compatible with R13SP1 and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

smoothmedian