HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulestatistics-0.16.3.0Haskell2010

Statistics.Quantile

Functions for approximating quantiles, i.e. points taken at regular intervals from the cumulative distribution function of a random variable.

The number of quantiles is described below by the variable q, so with q=4, a 4-quantile (also known as a quartile) has 4 intervals, and contains 5 points. The parameter k describes the desired point, where 0 ≤ k ≤ q.

  • 1 type
  • 1 class
  • 14 values

Quantile estimation functions

5 declarations

Below is family of functions which use same algorithm for estimation of sample quantiles. It approximates empirical CDF as continuous piecewise function which interpolates linearly between points (X_k,p_k) where X_k is k-th order statistics (k-th smallest element) and p_k is probability corresponding to it. ContParam determines how p_k is chosen. For more detailed explanation see [Hyndman1996].

This is the method used by most statistical software, such as R, Mathematica, SPSS, and S.

datadata ContParam
#

Parameters α and β to the continuousBy function. Exact meaning of parameters is described in [Hyndman1996] in section "Piecewise linear functions"

Constructors

Instances10Eq, Data, Ord, Show, Generic, Binary, …
classclass Default a where
#

A class for types with a default value.

Methods

  • def :: a

    The default value for this type.

Instances99Default, …
valuequantile
  1. :: Vector v Double
  2. => ContParam

    Parameters α and β.

  3. -> Int

    k, the desired quantile.

  4. -> Int

    q, the number of quantiles.

  5. -> v Double

    x, the sample data.

  6. -> Double
#

O(n·log n). Estimate the kth q-quantile of a sample x, using the continuous sample method with the given parameters.

The following properties should hold, otherwise an error will be thrown.

  • input sample must be nonempty

  • the input does not contain NaN

  • 0 ≤ k ≤ q

valuequantiles
  1. :: (Vector v Double, Foldable f, Functor f)
  2. => ContParam
  3. -> f Int
  4. -> Int
  5. -> v Double
  6. -> f Double
#

O(k·n·log n). Estimate set of the kth q-quantile of a sample x, using the continuous sample method with the given parameters. This is faster than calling quantile repeatedly since sample should be sorted only once

The following properties should hold, otherwise an error will be thrown.

  • input sample must be nonempty

  • the input does not contain NaN

  • for every k in set of quantiles 0 ≤ k ≤ q

Parameters for the continuous sample method

valuecadpw :: ContParam
#

California Department of Public Works definition, α=0, β=1. Gives a linear interpolation of the empirical CDF. This corresponds to method 4 in R and Mathematica.

valuehazen :: ContParam
#

Hazen's definition, α=0.5, β=0.5. This is claimed to be popular among hydrologists. This corresponds to method 5 in R and Mathematica.

valuespss :: ContParam
#

Definition used by the SPSS statistics application, with α=0, β=0 (also known as Weibull's definition). This corresponds to method 6 in R and Mathematica.

values :: ContParam
#

Definition used by the S statistics application, with α=1, β=1. The interpolation points divide the sample range into n-1 intervals. This corresponds to method 7 in R and Mathematica and is default in R.

Median unbiased definition, α=1/3, β=1/3. The resulting quantile estimates are approximately median unbiased regardless of the distribution of x. This corresponds to method 8 in R and Mathematica.

Normal unbiased definition, α=3/8, β=3/8. An approximately unbiased estimate if the empirical distribution approximates the normal distribution. This corresponds to method 9 in R and Mathematica.

Other algorithms

1 declaration
valueweightedAvg
  1. :: Vector v Double
  2. => Int

    k, the desired quantile.

  3. -> Int

    q, the number of quantiles.

  4. -> v Double

    x, the sample data.

  5. -> Double
#

O(n·log n). Estimate the kth q-quantile of a sample, using the weighted average method. Up to rounding errors it's same as quantile s.

The following properties should hold otherwise an error will be thrown.

  • the length of the input is greater than 0

  • the input does not contain NaN

  • k ≥ 0 and k ≤ q

Median & other specializations

3 declarations
valuemad
  1. :: Vector v Double
  2. => ContParam

    Parameters α and β.

  3. -> v Double

    x, the sample data.

  4. -> Double
#

O(n·log n). Estimate the median absolute deviation (MAD) of a sample x using continuousBy. It's robust estimate of variability in sample and defined as:

MAD = \operatorname{median}(| X_i - \operatorname{median}(X) |)

valuemidspread
  1. :: Vector v Double
  2. => ContParam

    Parameters α and β.

  3. -> Int

    q, the number of quantiles.

  4. -> v Double

    x, the sample data.

  5. -> Double
#

O(n·log n). Estimate the range between q-quantiles 1 and q-1 of a sample x, using the continuous sample method with the given parameters.

For instance, the interquartile range (IQR) can be estimated as follows:

midspread medianUnbiased 4 (U.fromList [1,1,2,2,3])
==> 1.333333

Deprecated

1 declaration

References

0 declarations