Robust location estimators

Robust alternatives to the sample mean, in robustmodels.location.

Choosing an estimator

Function

Breakdown point

Gaussian efficiency

Notes

hodges_lehmann

29.3%

95.5%

No tuning; a good default

m_location (Huber)

50%

95%

Monotone psi; flat sets of solutions are possible

m_location (bisquare)

50%

95%

Rejects gross outliers completely

tau_location

50%

One weighted mean; no iteration

trimmed_mean

proportion

Removes the tails

winsorized_mean

proportion

Clips the tails

The percentages are asymptotic under the relevant assumptions. The M-location values assume the default robust scale and tuning. The median itself (numpy.median) has a 50% asymptotic breakdown point and 64% Gaussian efficiency.

Use

>>> from robustmodels import location
>>> x = [1, 2, 2, 3, 4, 100]
>>> location.hodges_lehmann(x)
3.0
>>> round(location.m_location(x), 4)
2.7988
>>> round(location.m_location(x, psi="bisquare"), 4)
2.3869
>>> round(location.tau_location(x), 4)
2.3918

Trimming works with whole observations: it removes floor(proportion * n) values from each end, so the default 10% removes nothing from a sample of six.

>>> round(location.trimmed_mean(x), 4)
18.6667
>>> location.trimmed_mean(x, proportion=0.2)
2.75
>>> round(location.winsorized_mean(x, proportion=0.2), 4)
2.8333

m_location keeps the scale fixed. By default it is the MAD; pass another estimate with scale:

>>> from robustmodels import scale
>>> round(location.m_location(x, scale=scale.qn(x)), 4)
2.7655

Numerical conventions and sources

m_location uses a fixed scale and starts from the median. A zero scale returns the median. Bisquare can have multiple stationary solutions; a local iteration does not certify a global minimum. If the requested iteration limit is reached, the last location is returned with a RuntimeWarning. Huber’s monotone score can also have an interval of roots rather than a unique root.

The Hodges–Lehmann estimator includes diagonal pairs. Its current sorted-row selector uses O(n log² n) time and O(n) auxiliary storage. It computes the specified median in floating-point arithmetic.

Sources: Hodges–Lehmann, Huber, Beaton–Tukey, Tukey–McLaughlin, and Maronna–Zamar.

Reference

hodges_lehmann(x)[source]

Hodges-Lehmann estimator: the median of the Walsh averages.

Median of (x_i + x_j) / 2 over i <= j. Breakdown point 29.3%, Asymptotic Gaussian efficiency 95.5%. The current sorted-row selection uses O(n log^2 n) time and O(n) auxiliary storage.

Parameters:

x (array_like) – One-dimensional sample of finite values.

Returns:

nan for an empty sample.

Return type:

float

References

Hodges, J. L. and Lehmann, E. L. (1963). Estimates of location based on rank tests. Annals of Mathematical Statistics, 34(2), 598-611.

Examples

>>> from robustmodels.location import hodges_lehmann
>>> hodges_lehmann([1, 2, 2, 3, 4, 100])
3.0
m_location(x, *, psi='huber', c=None, scale=None, tol=1e-09, max_iter=500)[source]

M-estimator of location with Huber’s or Tukey’s bisquare psi function.

Solves sum(psi((x_i - mu) / s)) = 0 for mu by iteration from the median, with the scale s held fixed. With the MAD as scale the breakdown point is 50%; the default tuning constants give 95% Gaussian efficiency.

Parameters:
  • x (array_like) – One-dimensional sample of finite values.

  • psi ({"huber", "bisquare"}, default "huber") – Huber’s monotone psi or Tukey’s redescending bisquare psi.

  • c (float, optional) – Tuning constant. Defaults to 1.345 for “huber” and 4.685 for “bisquare”.

  • scale (float, optional) – Fixed scale s. Defaults to the MAD about the median. A zero scale returns the median.

  • tol (float, default 1e-9) – Stop when the location changes by less than tol * s.

  • max_iter (int, default 500) – Maximum number of iterations. Warns if the stopping criterion is not met.

Returns:

nan for an empty sample. If the bisquare gives every observation zero weight, the current location is returned.

Return type:

float

References

Huber, P. J. (1964). Robust estimation of a location parameter. Annals of Mathematical Statistics, 35(1), 73-101.

Beaton, A. E. and Tukey, J. W. (1974). The fitting of power series, meaning polynomials, illustrated on band-spectroscopic data. Technometrics, 16(2), 147-185.

Examples

>>> from robustmodels.location import m_location
>>> round(m_location([1, 2, 2, 3, 4, 100]), 4)
2.7988
>>> round(m_location([1, 2, 2, 3, 4, 100], psi="bisquare"), 4)
2.3869
tau_location(x, *, c1=4.5)[source]

Tau location of Maronna & Zamar (2002): one bisquare-weighted mean.

Weighted mean with weights (1 - (r_i / c1)^2)^2 for |r_i| < c1 and 0 otherwise, where r_i = (x_i - median) / MAD0 and MAD0 is the raw (unscaled) MAD. This is the location used by robustmodels.scale.tau_scale(). Returns the median if MAD0 is zero or every weight is zero.

Parameters:
  • x (array_like) – One-dimensional sample of finite values.

  • c1 (float, default 4.5) – Bisquare tuning constant.

Returns:

nan for an empty sample.

Return type:

float

References

Maronna, R. A. and Zamar, R. H. (2002). Robust estimates of location and dispersion for high-dimensional datasets. Technometrics, 44(4), 307-317.

Examples

>>> from robustmodels.location import tau_location
>>> round(tau_location([1, 2, 2, 3, 4, 100]), 4)
2.3918
trimmed_mean(x, proportion=0.1)[source]

Trimmed mean, as scipy.stats.trim_mean.

Mean after removing floor(proportion * n) observations from each end of the sorted sample. Breakdown point close to proportion.

Parameters:
  • x (array_like) – One-dimensional sample of finite values.

  • proportion (float in [0, 0.5), default 0.1) – Fraction removed from each end.

Returns:

nan for an empty sample.

Return type:

float

References

Tukey, J. W. and McLaughlin, D. H. (1963). Less vulnerable confidence and significance procedures for location based on a single sample: Trimming/ Winsorization 1. Sankhya, Series A, 25(3), 331-352.

Examples

>>> from robustmodels.location import trimmed_mean
>>> trimmed_mean([1, 2, 2, 3, 4, 100], proportion=0.2)
2.75
winsorized_mean(x, proportion=0.1)[source]

Winsorized mean.

Mean after replacing the k = floor(proportion * n) smallest observations by the (k + 1)-th smallest, and the k largest by the (k + 1)-th largest. Breakdown point close to proportion.

Parameters:
  • x (array_like) – One-dimensional sample of finite values.

  • proportion (float in [0, 0.5), default 0.1) – Fraction clipped at each end.

Returns:

nan for an empty sample.

Return type:

float

References

Tukey, J. W. and McLaughlin, D. H. (1963). Less vulnerable confidence and significance procedures for location based on a single sample: Trimming/ Winsorization 1. Sankhya, Series A, 25(3), 331-352.

Examples

>>> from robustmodels.location import winsorized_mean
>>> round(winsorized_mean([1, 2, 2, 3, 4, 100], proportion=0.2), 4)
2.8333