leave_one_out: Compute Leave-One-Out Cross-Validated Predictions

View source: R/leave_one_out.R

leave_one_outR Documentation

Compute Leave-One-Out Cross-Validated Predictions

Description

Computes leave-one-out cross-validated predictions from a fitted lgspline object. For additive_lgspline fits, the calculation constructs the full appended additive design matrix, combines term penalties and active constraints, and computes the hat diagonal from that single dense system.

The LOO shortcut is \hat{y}_{(-i)} = y_i - (y_i - \hat{y}_i)/(1 - H_{ii}), where \mathbf{H} is the effective hat matrix adjusted for weights and correlation structure when present.

Observations with leverage at or above leverage_threshold are flagged in a warning, since extreme hat values can make the calculation numerically unreliable.

Usage

leave_one_out(model_fit, leverage_threshold = 100)

Arguments

model_fit

A fitted lgspline or additive_lgspline object.

leverage_threshold

Numeric scalar. Observations with H_{ii} \geq leverage_threshold are treated as high leverage. Default 100.

Value

A vector of leave-one-out cross-validated predictions.

References

Tarpey, T. (2000). A note on the prediction sum of squares statistic for restricted least squares. The American Statistician, 54(2), 116–118. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2686028")}

Examples

set.seed(1234)
t <- rnorm(50)
y <- sin(t) + rnorm(50, 0, .25)
model_fit <- lgspline(t, y)
loo <- leave_one_out(model_fit)
press <- mean((y - loo)^2, na.rm = TRUE)

plot(loo, y,
  main = "LOO Cross-Validation Prediction vs. Observed Response",
  xlab = "Prediction", ylab = "Response")
abline(0, 1)


lgspline documentation built on Aug. 5, 2026, 1:10 a.m.