Function Repository Resource:

MedianQuantileAround

Source Notebook

Calculate the median of a list along with its uncertainty

Contributed by: Ting Sun

ResourceFunction["MedianQuantileAround"][{x1,x2,}]

gives an Around object whose value is the median of the xi and whose uncertainty is the interquartile range.

ResourceFunction["MedianQuantileAround"][{x1,x2,},δ]

gives an Around object with uncertainty specified by δ.

ResourceFunction["MedianQuantileAround"][{x1,x2,},{δ-,δ+}]

gives an Around object with upper and lower uncertainties specified by δ- and δ+.

Details and Options

The "value" part of the Around object retured is calculated using the built-in Median and Quantile functions.
ResourceFunction["MedianQuantileAround"][{x1,x2,},δ] is defined to be {Quantile[{x1,},0.5+δ]-Median[{x1,}],Quantile[{x1,},0.5-δ]-Median[{x1,}]}.
ResourceFunction["MedianQuantileAround"][{x1,x2,},{δ-,δ+}] is defined to be {Quantile[{x1,},0.5-δ-]-Median[{x1,}],Quantile[{x1,},0.5+δ+]-Median[{x1,}]}.

Examples

Basic Examples (1) 

Calculate the median of some numbers with uncertainty represented by interquartile range:

In[1]:=
ResourceFunction[
 "MedianQuantileAround"][{1.1, 2.2, 2.6, 1.4, 2.2, 2.3}]
Out[1]=

Scope (2) 

The size of the inter-quantile range to use can be specified as a second argument:

In[2]:=
list = {1.1, 2.2, 2.6, 1.4, 2.2, 2.3};
ResourceFunction["MedianQuantileAround"][list, .25] == ResourceFunction["MedianQuantileAround"][list]
Out[2]=

MedianQuantileAround also works on quantities with units:

In[3]:=
ResourceFunction[
 "MedianQuantileAround"][{Quantity[1, "Meters"], Quantity[1.1, "Meters"], Quantity[0.98, "Meters"], Quantity[0.99, "Meters"]}]
Out[3]=

Possible Issues (1) 

MedianQuantileAround does not work with symbolic expressions:

In[4]:=
ResourceFunction[
 "MedianQuantileAround"][{a, b, c, d, e, f, g, h, i, j, k, l}]
Out[4]=

Publisher

Ting Sun

Version History

  • 1.0.0 – 17 April 2020

Related Resources

License Information