linear_reg_lts: Robust Linear Regression in tidymodels (LTS parsnip Engine)

linear_reg_ltsR Documentation

Robust Linear Regression in tidymodels (LTS parsnip Engine)

Description

specProc adds the "lts" engine to parsnip::linear_reg(): the reweighted least trimmed squares (LTS) regression of robustbase::ltsReg(), which resists vertical outliers and bad leverage points. lts_fit() fits it outside of tidymodels.

Usage

lts_fit(x, y, alpha = 0.75, nsamp = 500)

Arguments

x

A numeric matrix or data frame of the predictors.

y

A numeric vector of the response.

alpha

The fraction of observations whose squared residuals are minimized, between 0.5 and 1. Default is 0.75.

nsamp

The number of random subsets. Default is 500.

Details

The engine is available once parsnip and specProc are both loaded, in either order. It is for regression with one outcome.

Combined with step_robpca() in a workflow, it gives the robust principal component regression of Hubert and Verboven (2003), whose robust PCA has num_comp components (see also rpcr()): the robust scores of the spectra, then the LTS regression on them. It also gives robust calibration curves from a few line intensities.

Value

lts_fit() returns an object of class specproc_lts, a list with the coefficients (intercept first), their standard errors std_error and the residual degrees of freedom df_residual of the reweighted least-squares fit, the robust r_squared, the robust scale of the residuals, the fitted values, residuals, standardized residuals std_resid and the weights of the reweighted fit (1 for the observations whose standardized residual is within the cut-off). Its predict() method takes newdata, and tidy() and glance() summarize it (see specproc-tidy-models).

Engine arguments

  • alpha: the fraction of observations whose squared residuals are minimized, between 0.5 and 1 (default 0.75, as in rpcr()).

  • nsamp: the number of random subsets (default 500).

The main arguments of parsnip::linear_reg(), penalty and mixture, are not used. LTS uses random subsets, so use set.seed() before fitting for reproducible results.

Author(s)

Christian L. Goueguel

References

  • Rousseeuw, P.J., Van Driessen, K. (2006). Computing LTS regression for large data sets. Data Mining and Knowledge Discovery, 12(1):29-45.

  • Hubert, M., Verboven, S. (2003). A robust PCR method for high-dimensional regressors. Journal of Chemometrics, 17(8-9):438-452.

See Also

rpcr(), step_robpca(), parsnip::linear_reg()

Examples


library(parsnip)
data(forageLIBS)
lines <- forageLIBS[c("Ca", "393.3599236", "396.8602175")]  # Ca II K and H
names(lines) <- c("Ca", "CaII_393", "CaII_397")
set.seed(1)
fit <- linear_reg() |>
  set_engine("lts") |>
  fit(Ca ~ ., data = lines[1:300, ])
predict(fit, lines[301:305, ])
extract_fit_engine(fit)$coefficients


specProc documentation built on Nov. 20, 2026, 5:11 p.m.