View source: R/leave_one_out.R
| leave_one_out | R Documentation |
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.
leave_one_out(model_fit, leverage_threshold = 100)
model_fit |
A fitted |
leverage_threshold |
Numeric scalar. Observations with
|
A vector of leave-one-out cross-validated predictions.
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")}
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.