Function Repository Resource:

Decile

Source Notebook

Get the decile values of a list of data

Contributed by: Sander Huisman

ResourceFunction["Decile"][data]

gives the 0th to the 10th decile value of data as an assocation.

ResourceFunction["Decile"][data,n]

gives the nth decile value of data.

ResourceFunction["Decile"][data,{n1,n2,n3,}]

gives an Association of the nith decile values of data.

Details

In descriptive statistics, a decile value corresponds to the boundaries of 10% of the data after it is sorted. The first decile corresponds to the value for which 10% of the data is lower than it, and 90% higher. The second decile corresponds to the value for which 20% of the data is lower than it, and 80% higher, etc.
The 0th decile corresponds to the minimum of the data. The 10th decile corresponds to the maximum of the data.
The 5th decile corresponds to the median of the data.
The nth decile corresponds to the 0.1n quantile value of the data.
Decile only supports numeric data.

Examples

Basic Examples (3) 

Find the decile values of some data:

In[1]:=
ResourceFunction["Decile"][Range[0, 1000]]
Out[1]=

Find the 7th decile:

In[2]:=
ResourceFunction["Decile"][RandomReal[{0, 1}, 1000], 7]
Out[2]=

Find the 1st and 9th decile:

In[3]:=
ResourceFunction["Decile"][
 RandomVariate[NormalDistribution[], 1000], {1, 9}]
Out[3]=

Scope (1) 

The second argument does not have to be an integer, and can be used to reproduce the interquartile range (IQR):

In[4]:=
d = RandomReal[{0, 1}, 1000];
{ResourceFunction["Decile"][d, 7.5] - ResourceFunction["Decile"][d, 2.5], InterquartileRange[d, {{0, 0}, {1, 0}}]}
Out[5]=

Applications (2) 

Compute the decile mean of some data:

In[6]:=
decilemean[data_List] := Mean[ResourceFunction["Decile"][data, Range[1, 9]]]
decilemean[RandomVariate[NormalDistribution[], 777]]
Out[7]=

Get a quick idea of the deciles of a list of numbers (e.g. shoe sizes):

In[8]:=
d = RandomVariate[SkewNormalDistribution[41, 1, 2], 100000];
ResourceFunction["Decile"][d] // Dataset
Out[9]=

Properties and Relations (3) 

In[10]:=
d = RandomVariate[NormalDistribution[], 777];

The 5th decile is related to Median and Quantile:

In[11]:=
{Median[d], Quantile[d, 0.5], ResourceFunction["Decile"][d, 5]}
Out[11]=

The 0th decile is related to the minimum value:

In[12]:=
{ResourceFunction["Decile"][d, 0], Min[d]}
Out[12]=

The 10th decile is related to the maximum value:

In[13]:=
{ResourceFunction["Decile"][d, 10], Max[d]}
Out[13]=

Possible Issues (2) 

The second argument has to be non-negative:

In[14]:=
d = {76, 21, 48, 100, 5, 39, 62, 78, 7, 27, 86, 100, 91, 5, 27, 89, 12};
ResourceFunction["Decile"][d, -1]
Out[15]=

The second argument must be equal or less than 10:

In[16]:=
d = {76, 21, 48, 100, 5, 39, 62, 78, 7, 27, 86, 100, 91, 5, 27, 89, 12};
ResourceFunction["Decile"][d, 10.5]
Out[17]=

Publisher

SHuisman

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 14 August 2024

Related Resources

License Information