pingouin.harrelldavis

pingouin.harrelldavis(x, quantile=0.5, axis=-1)[source]

Harrell-Davis robust estimate of the \(q^{th}\) quantile(s) of the data.

New in version 0.2.9.

Parameters
xarray_like

Data, must be a one or two-dimensional vector.

quantilefloat or array_like

Quantile or sequence of quantiles to compute, must be between 0 and 1. Default is 0.5.

axisint

Axis along which the MAD is computed. Default is the last axis (-1). Can be either 0, 1 or -1.

Returns
yfloat or array_like

The estimated quantile(s). If quantile is a single quantile, will return a float, otherwise will compute each quantile separately and returns an array of floats.

See also

plot_shift

Shift function.

Notes

The Harrell-Davis method [1] estimates the \(q^{th}\) quantile by a linear combination of the order statistics. Results have been tested against the Matlab implementation proposed by [2]. This method is also used to measure the confidence intervals of the difference between quantiles of two groups, as implemented in the shift function [3].

References

1

Frank E. Harrell, C. E. Davis, A new distribution-free quantile estimator, Biometrika, Volume 69, Issue 3, December 1982, Pages 635–640, https://doi.org/10.1093/biomet/69.3.635

2

https://github.com/GRousselet/matlab_stats/blob/master/hd.m

3

Rousselet, G. A., Pernet, C. R. and Wilcox, R. R. (2017). Beyond differences in means: robust graphical methods to compare two groups in neuroscience. Eur J Neurosci, 46: 1738-1748. https://doi.org/doi:10.1111/ejn.13610

Examples

Estimate the 0.5 quantile (i.e median) of 100 observation picked from a normal distribution with mean=0 and std=1.

>>> import numpy as np
>>> import pingouin as pg
>>> np.random.seed(123)
>>> x = np.random.normal(0, 1, 100)
>>> pg.harrelldavis(x, quantile=0.5)
-0.04991656842939151

Several quantiles at once

>>> pg.harrelldavis(x, quantile=[0.25, 0.5, 0.75])
array([-0.84133224, -0.04991657,  0.95897233])

On the last axis of a 2D vector (default)

>>> np.random.seed(123)
>>> x = np.random.normal(0, 1, (10, 100))
>>> pg.harrelldavis(x, quantile=[0.25, 0.5, 0.75])
array([[-0.84133224, -0.52346777, -0.81801193, -0.74611216, -0.64928321,
        -0.48565262, -0.64332799, -0.8178394 , -0.70058282, -0.73088088],
       [-0.04991657,  0.02932655, -0.08905073, -0.1860034 ,  0.06970415,
         0.15129817,  0.00430958, -0.13784786, -0.08648077, -0.14407123],
       [ 0.95897233,  0.49543002,  0.57712236,  0.48620599,  0.85899005,
         0.7903462 ,  0.76558585,  0.62528436,  0.60421847,  0.52620286]])

On the first axis

>>> pg.harrelldavis(x, quantile=[0.5], axis=0).shape
(100,)