Algorithm Search⌘K

Algorithmcore

Tukey's biweight

Also called Tukey bisquare, bisquare estimator.

A redescending M-estimator whose psi function goes to zero beyond a threshold, so gross outliers get no weight. Fitted by iteratively reweighted least squares.

Time
Θ(n log n + n t) worst · averageΘ(n log n) best
Space
Θ(n) extra
Where
n = the sample size; t = the number of reweighting steps
Properties
deterministicnot exact in exact arithmeticnot in placeofflinenot randomized
Origin
Albert E. Beaton, John W. Tukey, 1974

Tukey's biweight is the M-estimator of location with the loss ρc(u)=c26[1−(1−(u/c)2)3]\rho_c(u) = \frac{c^2}{6}\bigl[1 - (1 - (u/c)^2)^3\bigr] for ∣u∣≤c|u| \le c and ρc(u)=c2/6\rho_c(u) = c^2/6 beyond. Its derivative ψc(u)=u(1−(u/c)2)2\psi_c(u) = u(1 - (u/c)^2)^2 rises, falls back, and is exactly 0 for ∣u∣≥c|u| \ge c. So a point farther than cσ^c\hat\sigma from the estimate has no influence at all. The loss is not convex, so the estimate is computed by iteratively reweighted means from a robust start, the median, with the scale fixed at the normalized MAD. Each step does not increase the objective. With c=4.685c = 4.685 the efficiency at the normal is 95%.

In plain words

Each point gets a weight between 0 and 1. A point near the current center gets a weight close to 1. A point farther away gets a smaller weight, and a point beyond a cutoff gets weight 0. The new center is the weighted average of the points. Then the weights are computed again for the new center, and so on until the center stops moving. A point far from the bulk of the data is not only weakened, it is ignored. The cutoff is a number of typical spreads, measured with a robust spread.

The problem

The input is a sample x1,…,xnx_1, \ldots, x_n, a constant c>Φ−1(3/4)≈0.6745c > \Phi^{-1}(3/4) \approx 0.6745 (the default is c=4.685c = 4.685) and a tolerance. The scale is σ^=MAD/Φ−1(3/4)\hat\sigma = \mathrm{MAD}/\Phi^{-1}(3/4). The target is a local minimizer of

Q(θ)=∑i=1nρc ⁣(xi−θσ^),Q(\theta) = \sum_{i=1}^n \rho_c\!\left(\frac{x_i - \theta}{\hat\sigma}\right),

that is a root of ∑iψc((xi−θ)/σ^)=0\sum_i \psi_c((x_i - \theta)/\hat\sigma) = 0, reached from the median. The output is the point where the iteration stops. QQ can have several local minima, and the method does not promise the global one.

The algorithm

The weight function is wc(u)=ψc(u)/u=(1−(u/c)2)2w_c(u) = \psi_c(u)/u = (1 - (u/c)^2)^2 for ∣u∣<c|u| < c and 0 otherwise.

  1. BIWEIGHT(x, c, tol) ▷ x[1 .. n]
  2. 1θ ← median(x); σ ← MAD(x)/Φ⁻¹(3/4); if σ = 0 then return θ
  3. 2repeat
  4. 3r_i ← (x_i − θ)/σ for each i
  5. 4w_i ← (1 − (r_i/c)²)² if |r_i| < c, else 0
  6. 5θ' ← Σ w_i x_i / Σ w_i
  7. 6if |θ' − θ| ≤ tol · σ then return θ'
  8. 7θ ← θ'

A fixed point of lines L3 to L5 satisfies ∑iwi(xi−θ)=0\sum_i w_i (x_i - \theta) = 0, which is σ^∑iψc(ri)=0\hat\sigma \sum_i \psi_c(r_i) = 0. So the method stops near a root of the estimating equation.

Example

Take x=(2,4,5,6,7,30)x = (2, 4, 5, 6, 7, 30) and c=4.685c = 4.685. The median is 5.55.5. The absolute deviations are (3.5,1.5,0.5,0.5,1.5,24.5)(3.5, 1.5, 0.5, 0.5, 1.5, 24.5), so the MAD is 1.51.5 and σ^=1.5/0.6745=2.2239\hat\sigma = 1.5/0.6745 = 2.2239. Then cσ^=10.42c\hat\sigma = 10.42, and the point 30 is beyond the cutoff from the start.

step θ\theta weights of (2,4,5,6,7,30)(2, 4, 5, 6, 7, 30) Q(θ)Q(\theta) ∑ψc\sum \psi_c
0 5.5 0.787, 0.959, 0.995, 0.995, 0.959, 0 5.2582 −1.2387-1.2387
1 4.9134 0.850, 0.985, 1.000, 0.978, 0.921, 0 5.0762 −0.1361-0.1361
2 4.8494 5.0741
3 4.8425 5.0740

The iteration stops after 13 steps at θ^=4.8416\hat\theta = 4.8416, with ∣∑ψc∣<10−12|\sum \psi_c| < 10^{-12}. It is the mean of the first five points weighted almost equally. The value 30 has no effect: moving it to 10910^9 gives the same result. The mean is 9 and the median is 5.55.5.

Correctness

Two facts make the iteration safe, and proofs/correctness.md proves both. First, ρc(u)=g(u2)\rho_c(u) = g(u^2) with gg concave and nondecreasing on [0,∞)[0, \infty), and wc(u)=2g′(u2)w_c(u) = 2g'(u^2). A concave function lies below its tangent, so QQ lies below a weighted sum of squares that touches it at the current θ\theta. Line L5 minimizes that sum of squares. So Q(θ′)≤Q(θ)Q(\theta') \le Q(\theta), with equality only when θ′=θ\theta' = \theta. Second, the sum of the weights in line L5 is never 0. At the median, at least half of the points are within one MAD, that is within Φ−1(3/4) σ^<cσ^\Phi^{-1}(3/4)\,\hat\sigma < c\hat\sigma, so QQ at the start is less than nc2/6nc^2/6. If all weights were 0 at a later step, QQ would be nc2/6nc^2/6 there, against the descent. The proof also shows that every limit point of the iterates is a root of the estimating equation.

Proof: The biweight reweighting step never increases the objective and never divides by zerofull

Setting. x1,…,xnx_1, \ldots, x_n are real, c>qc > q where q=Φ−1(3/4)q = \Phi^{-1}(3/4), and σ=MAD/q>0\sigma = \mathrm{MAD}/q > 0 (the case σ=0\sigma = 0 ends at line L1). Write ri(θ)=(xi−θ)/σr_i(\theta) = (x_i - \theta)/\sigma, Q(θ)=∑iρc(ri(θ))Q(\theta) = \sum_i \rho_c(r_i(\theta)), and let T(θ)T(\theta) be the value θ′\theta' of line L5.

Lemma 1. Put g(s)=c26[1−(1−s/c2)3]g(s) = \frac{c^2}{6}\bigl[1 - (1 - s/c^2)^3\bigr] for 0≤s≤c20 \le s \le c^2 and g(s)=c2/6g(s) = c^2/6 for s>c2s > c^2. Then ρc(u)=g(u2)\rho_c(u) = g(u^2), gg is concave and nondecreasing on [0,∞)[0, \infty), it is differentiable, and 2g′(u2)=wc(u)2g'(u^2) = w_c(u).

Proof. The identity ρc(u)=g(u2)\rho_c(u) = g(u^2) is the definition. For s<c2s < c^2, g′(s)=12(1−s/c2)2g'(s) = \frac12(1 - s/c^2)^2, and for s>c2s > c^2, g′(s)=0g'(s) = 0. Both one-sided derivatives at s=c2s = c^2 are 0, so gg is differentiable with g′(s)=12max⁡(0,1−s/c2)2g'(s) = \frac12\max(0, 1 - s/c^2)^2. This function is nonnegative and nonincreasing, so gg is nondecreasing and concave. Finally 2g′(u2)=(1−u2/c2)2=wc(u)2g'(u^2) = (1 - u^2/c^2)^2 = w_c(u) for ∣u∣<c|u| < c, and both sides are 0 for ∣u∣≥c|u| \ge c. □\square

Lemma 2 (descent). If S(θ)=∑iwc(ri(θ))>0S(\theta) = \sum_i w_c(r_i(\theta)) > 0, then Q(T(θ))≤Q(θ)Q(T(\theta)) \le Q(\theta), with equality only if T(θ)=θT(\theta) = \theta.

Proof. Fix θ0\theta_0 with S(θ0)>0S(\theta_0) > 0, and put si=ri(θ0)2s_i = r_i(\theta_0)^2 and wi=wc(ri(θ0))=2g′(si)w_i = w_c(r_i(\theta_0)) = 2g'(s_i). A concave differentiable function lies below its tangent lines, so for every θ\theta

Q(θ)=∑ig(ri(θ)2)≤∑i[g(si)+12wi(ri(θ)2−si)]=:M(θ),Q(\theta) = \sum_i g(r_i(\theta)^2) \le \sum_i \Bigl[g(s_i) + \tfrac12 w_i\bigl(r_i(\theta)^2 - s_i\bigr)\Bigr] =: M(\theta),

with equality at θ=θ0\theta = \theta_0. MM is a quadratic in θ\theta with leading coefficient 12σ2∑iwi>0\frac{1}{2\sigma^2}\sum_i w_i > 0. Its derivative is −1σ2∑iwi(xi−θ)-\frac{1}{\sigma^2}\sum_i w_i(x_i - \theta), which is 0 at θ=∑iwixi/∑iwi=T(θ0)\theta = \sum_i w_i x_i / \sum_i w_i = T(\theta_0). So T(θ0)T(\theta_0) is the unique minimizer of MM, and

Q(T(θ0))≤M(T(θ0))≤M(θ0)=Q(θ0).Q(T(\theta_0)) \le M(T(\theta_0)) \le M(\theta_0) = Q(\theta_0).

The second inequality is strict if T(θ0)≠θ0T(\theta_0) \ne \theta_0, because the minimizer of MM is unique. □\square

Lemma 3 (positive weights). Let θ0\theta_0 be the median. Then Q(θ0)<nc2/6Q(\theta_0) < nc^2/6, and every iterate θt\theta_t has S(θt)>0S(\theta_t) > 0.

Proof. By the definition of the MAD, at least half of the points, and so at least one, satisfy ∣xi−θ0∣≤MAD=qσ|x_i - \theta_0| \le \mathrm{MAD} = q\sigma, that is ∣ri(θ0)∣≤q<c|r_i(\theta_0)| \le q < c. For such a point ρc(ri)<c2/6\rho_c(r_i) < c^2/6, and all other terms are at most c2/6c^2/6. So Q(θ0)<nc2/6Q(\theta_0) < nc^2/6. For any θ\theta, S(θ)=0S(\theta) = 0 means ∣ri(θ)∣≥c|r_i(\theta)| \ge c for all ii, so Q(θ)=nc2/6Q(\theta) = nc^2/6. By induction on tt: if S(θ0),…,S(θt−1)S(\theta_0), \ldots, S(\theta_{t-1}) are positive, Lemma 2 gives Q(θt)≤Q(θ0)<nc2/6Q(\theta_t) \le Q(\theta_0) < nc^2/6, so S(θt)>0S(\theta_t) > 0. □\square

Theorem. The iterates of lines L2 to L7 are well defined, Q(θt)Q(\theta_t) is nonincreasing, and every limit point θ∗\theta^* of (θt)(\theta_t) satisfies ∑iψc(ri(θ∗))=0\sum_i \psi_c(r_i(\theta^*)) = 0.

Proof. Lemma 3 shows that line L5 never divides by 0, and Lemma 2 gives the monotonicity. Each θt+1\theta_{t+1} is a weighted mean of the xix_i, so the iterates lie in [min⁡xi,max⁡xi][\min x_i, \max x_i], a compact set, and limit points exist. QQ is bounded below by 0, so Q(θt)Q(\theta_t) converges to some Q∗Q^*. Let θtj→θ∗\theta_{t_j} \to \theta^*. QQ is continuous, so Q(θ∗)=Q∗Q(\theta^*) = Q^*, and Q∗≤Q(θ0)<nc2/6Q^* \le Q(\theta_0) < nc^2/6, so S(θ∗)>0S(\theta^*) > 0. wcw_c is continuous (it is 0 at ±c\pm c), so TT is continuous at θ∗\theta^*, and T(θtj)=θtj+1→T(θ∗)T(\theta_{t_j}) = \theta_{t_j + 1} \to T(\theta^*). Then Q(T(θ∗))=lim⁡Q(θtj+1)=Q∗=Q(θ∗)Q(T(\theta^*)) = \lim Q(\theta_{t_j + 1}) = Q^* = Q(\theta^*). By Lemma 2, T(θ∗)=θ∗T(\theta^*) = \theta^*, that is ∑iwc(ri(θ∗))(xi−θ∗)=0\sum_i w_c(r_i(\theta^*))(x_i - \theta^*) = 0. Since wc(u) u=ψc(u)w_c(u)\,u = \psi_c(u), this is σ∑iψc(ri(θ∗))=0\sigma\sum_i \psi_c(r_i(\theta^*)) = 0. □\square

What is not claimed. The limit is a stationary point of QQ. It need not be the global minimizer, because QQ is not convex. The stopping rule of line L6 bounds the last step, not the distance to the limit.

Complexity

  • Time. The median and the MAD take Θ(nlog⁡n)\Theta(n \log n) by sorting, or expected Θ(n)\Theta(n) with quickselect. Each step takes Θ(n)\Theta(n). So the total is Θ(nlog⁡n+nt)\Theta(n \log n + nt) for tt steps.
  • Steps. The convergence is linear in general. The rate depends on the data: when almost all points have weight near 1, it is fast, and in the example the step length drops by about a factor 9 each step. No bound on tt in terms of nn alone holds.
  • Space. Θ(n)\Theta(n) for the weights.

Properties

The page proves the descent, the positive weights, and the bounded estimate for far outliers. The efficiency and the influence function are computed. The rest is cited.

  • Influence function. At the normal law with the scale fixed, IF(x)=σψc((x−μ)/σ)/Eψc′(Z)\mathrm{IF}(x) = \sigma\psi_c((x - \mu)/\sigma)/\mathrm E\psi_c'(Z). It is 0 for ∣x−μ∣≥cσ|x - \mu| \ge c\sigma: the rejection point is cσc\sigma. The largest value of ψc\psi_c is at u=c/5u = c/\sqrt5, and with c=4.685c = 4.685 the standardized gross-error sensitivity is 1.7701.770, against 1.6371.637 for the Huber estimator at 95% efficiency.
  • Efficiency at the normal. The asymptotic variance is Eψc(Z)2/(Eψc′(Z))2\mathrm E\psi_c(Z)^2/(\mathrm E\psi_c'(Z))^2 with ψc′(u)=(1−(u/c)2)(1−5(u/c)2)\psi_c'(u) = (1 - (u/c)^2)(1 - 5(u/c)^2) inside. A numerical integration gives 1.0526 for c=4.685c = 4.685, an efficiency of 0.950.
  • Far outliers are ignored (proved). Let c1c_1 and c2c_2 be the least and the greatest clean point, and let m<n/2m < n/2 points be replaced by values farther than cσ^c\hat\sigma from [c1,c2][c_1, c_2]. The median θ0\theta_0 is in [c1,c2][c_1, c_2], because more than half the points are clean. If θt∈[c1,c2]\theta_t \in [c_1, c_2], every replaced point has weight 0, so θt+1\theta_{t+1} is a weighted mean of clean points and is in [c1,c2][c_1, c_2]. So all iterates stay in [c1,c2][c_1, c_2]. The MAD of the sample is at most c2−c1c_2 - c_1 (the argument is on the Huber estimator page), so the condition holds when the replaced points are far enough. The tests move up to ⌈n/2⌉−1\lceil n/2 \rceil - 1 points to 10610^6 and 101210^{12} and measure that the estimate stays in [c1,c2][c_1, c_2]; at ⌈n/2⌉\lceil n/2 \rceil points it follows them.
  • Not convex. QQ is bounded, so it can have several local minima, for example one near each of two clusters. The root found depends on the start. This page does not prove a breakdown point for arbitrary replacements; for the global minimizer and for regression, see the cited books.
  • Equivariance. With the median start and the MAD scale, the computed estimate is location and scale equivariant.

Variants and improvements

  • Regression. Replace xi−θx_i - \theta by residuals yi−xiTβy_i - x_i^{\mathsf T}\beta and the weighted mean by weighted least squares; see iteratively reweighted least squares. A median start is not enough there; the MM-estimator supplies a high-breakdown start and scale.
  • The biweight midvariance. A scale estimate from the same weights, used together with the biweight location in exploratory work.
  • Other redescending functions. Hampel's three-part ψ\psi, Andrews' sine ψ(u)=sin⁡(u)\psi(u) = \sin(u) for ∣u∣≤π|u| \le \pi, and the Welsch weight e−u2/2e^{-u^2/2} behave in the same way.
  • One-step version. One Newton step from the median, with the derivative ∑ψc′(ri)\sum \psi_c'(r_i), gives the same first-order asymptotics if the derivative stays positive.
  • Choice of cc. Smaller values reject more points and lose efficiency at the normal. c=4.685c = 4.685 gives 95%. In units of the raw MAD this is 4.685×0.6745=3.164.685 \times 0.6745 = 3.16 MADs.

When to use it

Use the biweight when gross errors are expected and must have no influence, for example readings from a failing sensor or data entry errors. Use it with a good start and a robust scale. Use the Huber estimator when you want a convex problem with a unique answer. Use the median when the data are very dirty and efficiency matters less. In regression, use it only inside the MM-estimator or another high-breakdown method.

Pitfalls

  • Bad start. From the mean, or from a least squares fit, the iteration can converge to a root near the outliers. Always start from the median or another high-breakdown estimate.
  • Scale updated with the weights. If σ^\hat\sigma is recomputed from the weighted residuals at each step, the descent proof no longer holds, and the scale can implode. Fix it, or update it by an M-scale equation with its own proof.
  • Zero MAD. If more than half the values are equal, the MAD is 0 and the method returns the median.
  • Units of cc. Some texts give cc in units of the raw MAD, others in units of σ^=MAD/0.6745\hat\sigma = \mathrm{MAD}/0.6745. The value 4.685 is in units of σ^\hat\sigma.
  • Inference. With redescending ψ\psi the sum ∑ψc′(ri)\sum \psi_c'(r_i) can be small or negative in small samples, so the sandwich standard error can be unstable.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

tukey_biweight.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/tukey-biweight/. The authors are listed in prov/9NDW0S.jsonl.

from fractions import Fraction
from statistics import NormalDist

# Phi^{-1}(3/4): the MAD of N(0, 1).
Q3 = NormalDist().inv_cdf(0.75)


def weight(u, c):
    """Biweight weight psi(u)/u = (1 - (u/c)^2)^2 inside (-c, c), 0 outside."""
    if abs(u) >= c:
        return 0 * u
    t = 1 - (u / c) ** 2
    return t * t


def psi(u, c):
    return u * weight(u, c)


def rho(u, c):
    """Biweight loss (c^2/6)(1 - (1 - (u/c)^2)^3) inside, c^2/6 outside."""
    if abs(u) >= c:
        return c * c / 6
    return c * c / 6 * (1 - (1 - (u / c) ** 2) ** 3)


def exact_median(xs):
    s = sorted(xs)
    n = len(s)
    if n % 2 == 1:
        return s[n // 2]
    lo, hi = s[n // 2 - 1], s[n // 2]
    if isinstance(lo, (int, Fraction)) and isinstance(hi, (int, Fraction)):
        return Fraction(lo + hi, 2)
    return (lo + hi) / 2


def mad_scale(xs):
    m = exact_median(xs)
    return float(exact_median([abs(v - m) for v in xs])) / Q3


def objective(xs, theta, c, sigma):
    return sum(rho((v - theta) / sigma, c) for v in xs)


def biweight_step(xs, theta, c, sigma):
    """One reweighting step: the weighted mean with weights w((x_i - theta)/sigma)."""
    w = [weight((v - theta) / sigma, c) for v in xs]  # @line L4
    sw = sum(w)
    if sw == 0:
        raise ValueError("all weights are zero")
    return sum(wi * v for wi, v in zip(w, xs)) / sw  # @line L5


def biweight_location(xs, c=4.685, sigma=None, tol=1e-12, max_iter=1000, trace=None):
    """Tukey biweight M-estimate of location by IRLS from the median, with the scale fixed.

    sigma defaults to the normalized MAD. Returns a root of sum psi((x_i - theta)/sigma) = 0
    (up to tol); the objective does not increase along the iterates. If trace is a list,
    the iterates are appended to it. The iteration runs in floating point; use
    biweight_step for exact single steps.
    """
    x = [float(v) for v in xs]
    if not x:
        raise ValueError("empty sample")
    theta = exact_median(x)  # @line L1
    sigma = mad_scale(x) if sigma is None else float(sigma)  # @line L1
    c = float(c)
    if sigma == 0:
        return theta  # @line L1
    if trace is not None:
        trace.append(theta)
    for _ in range(max_iter):  # @line L2
        new = biweight_step(x, theta, c, sigma)  # @line L3
        if trace is not None:
            trace.append(new)
        if abs(new - theta) <= tol * sigma:  # @line L6
            return new
        theta = new  # @line L7
    return theta
test_tukey_biweight.py 114 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/tukey-biweight/. The authors are listed in prov/9NDW0S.jsonl.

import random
from fractions import Fraction
from statistics import NormalDist

import pytest

from tukey_biweight import (
    biweight_location, biweight_step, exact_median, mad_scale, objective, psi, weight,
)


def test_one_step_by_hand() -> None:
    # x = (2, 4, 5, 6, 7, 30), theta = 11/2, sigma = 2, c = 3.
    x = [2, 4, 5, 6, 7, 30]
    th = exact_median(x)
    assert th == Fraction(11, 2)
    w = [weight(Fraction(v - th) / 2, Fraction(3)) for v in x]
    assert w == [Fraction(9025, 20736), Fraction(225, 256), Fraction(20449, 20736),
                 Fraction(20449, 20736), Fraction(225, 256), 0]
    assert biweight_step(x, th, Fraction(3), Fraction(2)) == Fraction(63352, 12339)


def test_page_example() -> None:
    x = [2, 4, 5, 6, 7, 30]
    trace = []
    t = biweight_location(x, trace=trace)
    assert mad_scale(x) == pytest.approx(1.5 / 0.6744897501960817)
    assert [round(v, 4) for v in trace[:4]] == [5.5, 4.9134, 4.8494, 4.8425]
    assert t == pytest.approx(4.841634, abs=1e-6)
    # The point 30 has weight 0 at the end.
    assert weight((30 - t) / mad_scale(x), 4.685) == 0


def test_monotone_descent_and_stationarity() -> None:
    rng = random.Random(1)
    for _ in range(200):
        n = rng.randint(3, 40)
        x = [rng.gauss(0.0, 1.0) for _ in range(n)]
        for _ in range(rng.randint(0, n // 2 - 1 if n >= 4 else 0)):
            x[rng.randrange(n)] = rng.uniform(-100.0, 100.0)
        c = rng.choice([2.0, 3.0, 4.685, 6.0])
        sigma = mad_scale(x)
        trace = []
        t = biweight_location(x, c=c, trace=trace)
        if sigma == 0:
            continue
        q = [objective(x, v, c, sigma) for v in trace]
        assert all(b <= a + 1e-12 for a, b in zip(q, q[1:]))
        assert q[0] < n * c * c / 6  # the start has a point inside, so the weights stay positive
        assert abs(sum(psi((v - t) / sigma, c) for v in x)) <= 1e-8 * n


def test_exact_steps_do_not_increase_the_objective() -> None:
    rng = random.Random(2)
    for _ in range(60):
        n = rng.randint(2, 12)
        x = [rng.randint(-20, 20) for _ in range(n)] + [rng.randint(100, 200)]
        c, sigma = Fraction(rng.randint(2, 6)), Fraction(rng.randint(1, 5))
        th = exact_median(x)
        for _ in range(3):
            if sum(weight((v - th) / sigma, c) for v in x) == 0:
                break
            new = biweight_step(x, th, c, sigma)
            assert objective(x, new, c, sigma) <= objective(x, th, c, sigma)
            th = new


def test_far_outliers_have_no_influence() -> None:
    rng = random.Random(3)
    for _ in range(50):
        clean = [rng.gauss(10.0, 2.0) for _ in range(rng.randint(5, 30))]
        a = biweight_location(clean + [1e6, 2e6])
        b = biweight_location(clean + [1e9, 5e12])
        assert a == b


def test_efficiency_at_the_normal() -> None:
    # Simpson's rule: E psi^2 / (E psi')^2 = 1 / 0.95 for c = 4.685.
    phi = NormalDist().pdf
    c, m = 4.685, 4000
    h = 2 * c / m

    def simpson(f):
        s = f(-c) + f(c)
        for i in range(1, m):
            s += (4 if i % 2 else 2) * f(-c + i * h)
        return s * h / 3

    e2 = simpson(lambda z: psi(z, c) ** 2 * phi(z))
    e1 = simpson(lambda z: (1 - (z / c) ** 2) * (1 - 5 * (z / c) ** 2) * phi(z))
    assert e1 * e1 / e2 == pytest.approx(0.95, abs=1e-4)


def test_empirical_breakdown() -> None:
    rng = random.Random(4)
    for n in (5, 6, 9, 10, 15):
        clean_all = [rng.uniform(0.0, 10.0) for _ in range(n)]
        for s in (1e6, 1e12):
            for m in range((n + 1) // 2 + 1):
                clean = clean_all[: n - m]
                t = biweight_location(clean + [s] * m)
                if 2 * m < n:
                    assert min(clean) <= t <= max(clean)
                else:
                    assert t >= s / 4


def test_errors() -> None:
    with pytest.raises(ValueError):
        biweight_location([])
    assert biweight_location([4, 4, 4, 9]) == 4

History

Beaton and Tukey (1974) introduced the biweight to fit polynomials to band spectra that contained gross errors, and computed it by reweighting. Holland and Welsch (1977) studied iteratively reweighted least squares for the bisquare and other weight functions and the constants for 95% efficiency. Hampel, Ronchetti, Rousseeuw and Stahel (1986) placed redescending estimators in the influence function theory with the rejection point. Yohai (1987) used the biweight in the MM-estimator to obtain high breakdown and high efficiency together.

References

  1. Albert E. Beaton and John W. Tukey, The fitting of power series, meaning polynomials, illustrated on band-spectroscopic data, Technometrics 16(2), 1974, pp. 147 to 185 (the biweight weight function and its use in reweighted fits)
  2. Paul W. Holland and Roy E. Welsch, Robust regression using iteratively reweighted least-squares, Communications in Statistics, Theory and Methods 6(9), 1977, pp. 813 to 827 (iteratively reweighted least squares with the bisquare and other weight functions)
  3. Ricardo A. Maronna, R. Douglas Martin, Victor J. Yohai and Matías Salibián-Barrera, Robust Statistics, Theory and Methods (with R), second edition, Wiley, 2019, Chapter 2 (redescending M-estimators of location, the bisquare, the choice of c and the reweighting algorithm)
  4. Frank R. Hampel, Elvezio M. Ronchetti, Peter J. Rousseeuw and Werner A. Stahel, Robust Statistics, The Approach Based on Influence Functions, Wiley, 1986, Chapter 2 (redescending estimators and the rejection point)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example