statsmodels.tools.eval_measures.iqr#

statsmodels.tools.eval_measures.iqr(x1, x2, axis=0)[source]#

Interquartile range of error

Parameters:
x1array_like

One of the inputs into the IQR calculation.

x2array_like

The other input into the IQR calculation.

axisint or None, optional

Axis along which the summary statistic is calculated. If None, the differences are flattened and the interquartile range of all of them is returned.

Returns:
iqrfloat or ndarray of float

Interquartile range along given axis.

Notes

If x1 and x2 have different shapes, then they must broadcast. The quartiles are those of the broadcast difference x1 - x2.

The result is the difference between the order statistics at the 0-based positions round((n - 1) * 0.75) and round((n - 1) * 0.25) of the n sorted errors x1 - x2, where the rounding of a tie is to the even integer. There is no interpolation. This equals the difference between the quartiles of R’s IQR(type = 7) and of numpy.percentile with the default method if n = 1 (mod 4), where both positions are integers. For other n, for example 6 or 10, the results generally differ.

Changed in version 0.15.1: Inputs that are broadcast, an x1 of length 1 or a scalar x1, and axis=None with x1 and x2 of different shapes, now use the broadcast difference. They used to return 0 (length 1), or raise an error (scalar, and different shapes with axis=None).