image thumbnail

Weighted median (from data & sds) & its standard deviation

version (15.7 KB) by Bill Whiten
Interpolated weighted median with calculation of its standard deviation and distribution


Updated 26 Aug 2017

View License

Calculates weighted median using interpolation and optionally estimates standard deviation and distribution of median. Input is data and standard deviations of data points. If standard deviations not given normal mean is calculated.
The point indexes of the weights are placed symmetrically and interpolation for the 50% point, is used to give consistent results. If standard deviation of median is required, a weighted likelihood bootstrap calculates the mean and if required an empirical distribution of the median is returned.
Usage examples:
x=[1 2 3 4];
sd=[2 1 1 3];
wm =
wsd =
Can also use:
[wm,wsd]=wtmedian(x) % no (or unit) sds: usual median
wtmedian(x,sd) % gives median only, no bootstrap
cnt=10000;[wm,wed,dist]=wtmedian(x,sd,cnt) % additional bootstrap samples
For extra information:
doc wtmedian
Interpolation is used to avoid the existence of upper and lower weighted medians and instead give a consistent result (see The use of interpolation may give slightly different results from methods not using interpolation.
The point indices of the weights are placed so the the distribution of weights runs from 0.5 to n+0.5, similar to creating a bar graph of the weight distribution with the ith bar extending from i-0.5 to i+0.5, and then the cumulative distribution is the integral of this, and discrete values are read off at integer points. This distribution is the same if read from lower to higher values or higher to lower values.

The weighted likelihood bootstrap replaces integer repeat numbers for data points in the usual resampling bootstrap, with continuous values. see

Cite As

Bill Whiten (2021). Weighted median (from data & sds) & its standard deviation (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: weighted median

Community Treasure Hunt

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

Start Hunting!