Residual scale estimation during robustness iterations.
Overview
When Iterations > 0, LOWESS computes robustness weights by comparing each residual to the current residual scale estimate. The ScalingMethod parameter controls how that scale is measured.
The robustness weight for point $i$ is:
$$w_i = B\!\left(\frac{|r_i|}{6 \cdot \hat{\sigma}}\right)$$where $B$ is the bisquare function and $\hat{\sigma}$ is the scale estimate. A larger $\hat{\sigma}$ makes the algorithm more tolerant of large residuals; a smaller one makes it more aggressive.
| Method | Formula | Robustness | Speed |
|---|---|---|---|
"mad" | Median of |residuals − median(residuals)| | Very robust | Moderate |
"mar" | Median of |residuals| | Robust | Fast |
"mean" | Mean of |residuals| | Less robust | Fastest |
MAD — Median Absolute Deviation (Default)
$$\hat{\sigma} = \text{median}(|r_i - \text{median}(r_i)|)$$First centers residuals at their median, then takes the median of the absolute deviations. Double use of the median makes it highly resistant to extreme outliers. This is the standard choice for robust regression.
Use when: Data may contain outliers (default for most applications).
package main
import (
"fmt"
"log"
"math"
"github.com/thisisamirv/lowess-project/bindings/go/fastlowess/v5"
)
func main() {
n := 100
x := make([]float64, n)
y := make([]float64, n)
for i := 0; i < n; i++ {
x[i] = float64(i) * 2 * math.Pi / float64(n-1)
y[i] = math.Sin(x[i]) + 0.1
}
opts := fastlowess.DefaultOptions()
opts.Iterations = 3
opts.ScalingMethod = "mad"
model, err := fastlowess.NewLowess(opts)
if err != nil {
log.Fatal(err)
}
defer model.Close()
result, err := model.Fit(x, y)
if err != nil {
log.Fatal(err)
}
fmt.Println("First smoothed value (mad scaling):", result.Y[0])
}First smoothed value (mad scaling): 0.38088390025381585MAR — Median Absolute Residual
$$\hat{\sigma} = \text{median}(|r_i|)$$Uses the uncentered median — unlike MAD it does not subtract the residual median first. Still robust (median-based) but slightly less resistant than MAD when residuals are systematically shifted. Faster than MAD in practice because it requires only one partial sort.
Use when: Speed matters and data have minimal systematic bias in residuals.
package main
import (
"fmt"
"log"
"math"
"github.com/thisisamirv/lowess-project/bindings/go/fastlowess/v5"
)
func main() {
n := 100
x := make([]float64, n)
y := make([]float64, n)
for i := 0; i < n; i++ {
x[i] = float64(i) * 2 * math.Pi / float64(n-1)
y[i] = math.Sin(x[i]) + 0.1
}
opts := fastlowess.DefaultOptions()
opts.Iterations = 3
opts.ScalingMethod = "mar"
model, err := fastlowess.NewLowess(opts)
if err != nil {
log.Fatal(err)
}
defer model.Close()
result, err := model.Fit(x, y)
if err != nil {
log.Fatal(err)
}
fmt.Println("First smoothed value (mar scaling):", result.Y[0])
}First smoothed value (mar scaling): 0.3808839002538159Mean — Mean Absolute Residual
$$\hat{\sigma} = \frac{1}{n}\sum_i |r_i|$$Arithmetic mean of absolute residuals. Non-robust: a single extreme outlier inflates $\hat{\sigma}$, causing the algorithm to under-downweight it. Fastest to compute (no sort required). Useful when data are believed to be clean and speed is a priority.
Use when: Clean data with no outliers; maximum computation speed required.
package main
import (
"fmt"
"log"
"math"
"github.com/thisisamirv/lowess-project/bindings/go/fastlowess/v5"
)
func main() {
n := 100
x := make([]float64, n)
y := make([]float64, n)
for i := 0; i < n; i++ {
x[i] = float64(i) * 2 * math.Pi / float64(n-1)
y[i] = math.Sin(x[i]) + 0.1
}
opts := fastlowess.DefaultOptions()
opts.Iterations = 3
opts.ScalingMethod = "mean"
model, err := fastlowess.NewLowess(opts)
if err != nil {
log.Fatal(err)
}
defer model.Close()
result, err := model.Fit(x, y)
if err != nil {
log.Fatal(err)
}
fmt.Println("First smoothed value (mean scaling):", result.Y[0])
}First smoothed value (mean scaling): 0.3812865001248051Choosing a Scaling Method
| Situation | Recommended Method |
|---|---|
| General purpose, possible outliers | "mad" (default) |
| Speed matters; residuals have minimal systematic bias | "mar" |
| Clean data, no outliers | "mean" |
See Robustness for a broader discussion of outlier handling.