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

Version 1.0.0.0 (15.7 KB) by
Interpolated weighted median with calculation of its standard deviation and distribution

Updated 26 Aug 2017

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]=wtmedian(x,sd)
wm =
2.4167
wsd =
0.2610
[wm,wed,dist]=wtmedian(x,sd);
n=length(dist);plot(list,(1:n)/(n+1))
Can also use:
[wm,wsd]=wtmedian(x) % no (or unit) sds: usual median
wtmedian(x,sd) % gives median only, no bootstrap
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 https://en.wikipedia.org/wiki/Weighted_median). 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
https://www.stat.washington.edu/raftery/Research/PDF/newton1994.pdf
https://www.jstor.org/stable/3316141

### Cite As

Bill Whiten (2023). Weighted median (from data & sds) & its standard deviation (https://www.mathworks.com/matlabcentral/fileexchange/56712-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
##### Acknowledgements

Inspired by: weighted median

### Community Treasure Hunt

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

Start Hunting!

#### Weighted Median/

Version Published Release Notes
1.0.0.0

Changed wtmean.m to use parametric bootstrap to give closer agreement with standard deviation
updated image
Correction to bias in standard deviation calculation
Update image