Robustness
Outlier handling through iterative reweighting.
How Robustness Works
Standard LOWESS can be biased by outliers. Robustness iterations downweight points with large residuals:
- Fit initial LOWESS
- Compute residuals
- Assign robustness weights (large residuals → low weight)
- Refit using combined distance × robustness weights
- Repeat steps 2–4
Robustness Methods
Bisquare (Default)
Smooth downweighting. Points transition gradually from full weight to zero.
\[w(u) = \begin{cases} (1 - u^2)^2 & |u| < 1 \\ 0 & |u| \geq 1 \end{cases}\]
Use when: General purpose, balanced approach.
using FastLOWESS
using Random, Statistics
rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3
model = Lowess(; iterations=3, robustness_method="bisquare")
result = fit(model, x, y)
println("First smoothed value (bisquare robustness): ", result.y[1])First smoothed value (bisquare robustness): 0.4426033958974517Huber
Linear penalty beyond threshold. Less aggressive than Bisquare.
\[w(u) = \begin{cases} 1 & |u| \leq k \\ k/|u| & |u| > k \end{cases}\]
Use when: Moderate outliers, want to retain some influence.
using FastLOWESS
using Random, Statistics
rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3
model = Lowess(; iterations=3, robustness_method="huber")
result = fit(model, x, y)
println("First smoothed value (huber robustness): ", result.y[1])First smoothed value (huber robustness): 0.43650732026121564Talwar
Hard threshold. Points are either fully weighted or completely excluded.
\[w(u) = \begin{cases} 1 & |u| \leq k \\ 0 & |u| > k \end{cases}\]
Use when: Extreme outliers, want binary exclusion.
using FastLOWESS
using Random, Statistics
rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3
model = Lowess(; iterations=3, robustness_method="talwar")
result = fit(model, x, y)
println("First smoothed value (talwar robustness): ", result.y[1])First smoothed value (talwar robustness): 0.42875740979660093Comparison
| Method | Transition | Aggressiveness | Use Case |
|---|---|---|---|
| Bisquare | Smooth | Moderate | General purpose |
| Huber | Gradual | Mild | Preserve influence |
| Talwar | Hard | Strong | Extreme contamination |
Detecting Outliers
Use robustness weights to identify potential outliers:
using FastLOWESS
using Random, Statistics
rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3
model = Lowess(; iterations=5, outputs=["weights"])
result = fit(model, x, y)
shown = 0
for (i, w) in enumerate(result.robustness_weights)
global shown
if w < 0.5 && shown < 5
println("Potential outlier at index $i: weight = $w")
shown += 1
end
endPotential outlier at index 24: weight = 0.44572699983981534
Potential outlier at index 29: weight = 0.3857475192389485
Potential outlier at index 41: weight = 0.3814691920789072
Potential outlier at index 68: weight = 0.08122538921499627Scale Estimation
Residuals are scaled before computing robustness weights. Two methods:
| Method | Formula | Robustness |
|---|---|---|
| MAD | median(|r − median(r)|) | Very robust (default) |
| MAR | median(|r|) | Robust, uncentered |
| Mean | mean(|r|) | Less robust, fastest |
using FastLOWESS
using Random, Statistics
rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3
model = Lowess(; iterations=3, scaling_method="mad")
result = fit(model, x, y)
println("First smoothed value (MAD scaling): ", result.y[1])First smoothed value (MAD scaling): 0.4426033958974517Auto-Convergence
Stop iterations early when weights stabilize:
Auto-convergence can significantly reduce computation when weights stabilize before reaching max iterations.
using FastLOWESS
using Random, Statistics
rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3
model = Lowess(; iterations=10, auto_converge=1e-6)
result = fit(model, x, y)
println("First smoothed value (auto_converge enabled): ", result.y[1])First smoothed value (auto_converge enabled): 0.44247237863556826