Function Repository Resource:

QuantileOperator

Source Notebook

An operator form of the Quantile function

Contributed by: Seth J. Chandler

ResourceFunction["QuantileOperator"][q]

gives an operator for retrieving the qth quantile from data.

ResourceFunction["QuantileOperator"][q,{{a,b},{c,d}}]

uses the quantile definition specified by parameters a,b,c,d.

Details and Options

The data can be a List or statistical distribution.
The value of q should be between zero and one.
The effect of the various parameters is detailed in the documentation for the Quantile function.

Examples

Basic Examples (2) 

Create an operator that will find the halfway-value (median) of a List or statistical distribution:

In[1]:=
medianOperator = ResourceFunction["QuantileOperator"][1/2]
Out[1]=

Apply the operator to a List and a distribution:

In[2]:=
Map[medianOperator][{Range[7], LogNormalDistribution[a, b]}]
Out[2]=

Create an operator that computes lower and upper quartiles for whatever data it encounters, and then map it over multiple sets of data:

In[3]:=
Map[ResourceFunction["QuantileOperator"][{1/4, 3/4}]][{Range[7], LogNormalDistribution[a, b]}]
Out[3]=

Scope (2) 

Create an Association in which the keys are various parameters to the Quantile function and the values are each a corresponding QuantileOperator:

In[4]:=
quantileOperators75 = AssociationMap[
  params |-> ResourceFunction["QuantileOperator"][3/4, params], {{{0, 0}, {1, 0}}, {{0, 0}, {0, 1}}, {{1/2, 0}, {0, 0}}, {{1/2, 0}, {0, 1}}, {{0, 1}, {0, 1}}, {{1, -1}, {0, 1}}, {{1/3, 1/3}, {0, 1}}, {{3/8, 1/4}, {0, 1}}}]
Out[4]=

Apply the different QuantileOperator expressions to the same data to see how the choice of parameters affects the outcome:

In[5]:=
Map[#[Range[10]] &, quantileOperators75]
Out[5]=

Applications (2) 

Make a Histogram of the lower and upper quartiles of 100 random draws (10,000 samples) from a normal distribution:

In[6]:=
Histogram[
 Transpose[
  Map[ResourceFunction["QuantileOperator"][{0.25, 0.75}]][
   RandomVariate[NormalDistribution[0, 1], {10000, 100}]]], 100]
Out[6]=

Use quantile as a mesh function in drawing the PDF of a normal distribution:

In[7]:=
With[{\[ScriptCapitalD] = NormalDistribution[3, 1]}, Plot[PDF[\[ScriptCapitalD], x], {x, 0, 6}, Mesh -> {ResourceFunction["QuantileOperator"][
      Range[0.1, 0.9, 0.1]][\[ScriptCapitalD]]}, Sequence[
  Ticks -> {Automatic, None}, MeshFunctions -> {#& }, MeshStyle -> Black, MeshShading -> ColorData[97, "ColorList"], PlotStyle -> Thick]]
 ]
Out[7]=

Properties and Relations (2) 

QuantileOperator when used with a single argument is equivalent (as of version 12.0) to Curry[Quantile]:

In[8]:=
{Curry[Quantile][0.8][Range[10]], ResourceFunction["QuantileOperator"][0.8][Range[10]]}
Out[8]=

QuantileOperator[0.5,{{1/3,1/3},{0,1}}] is equivalent to Median:

In[9]:=
median = ResourceFunction["QuantileOperator"][
  1/2, {{1/3, 1/3}, {0, 1}}]
Out[9]=
In[10]:=
Outer[Construct, {median, Median}, {Range[10], Range[11], RandomReal[{0, 1}, 100], RandomReal[{0, 1}, 101]}, 1, 1]
Out[10]=

Publisher

Seth J. Chandler

Version History

  • 1.0.0 – 17 December 2019

License Information