Helper function to do a LOOCV on a gam or lm model

loogam(mod, k = 1, n = 100, LOO = FALSE)

Arguments

mod

A model returned by a gam or lm fit

k

folds. k=1 is LOO, k=2 is LTO

n

samples. How many folds to use.

LOO.

Whether to return the LOO RSME and MdAE for the LOO models. If set to TRUE, function will be slow.

Value

A list with predictions (fitted), actual, errors (fitted-actual), MAE and RMSE. Also AIC and AICc are returned for the LOO models.

Examples

# some simulated data with one cov library(mgcv) dat <- gamSim(6,n=100,scale=.5)[,1:2]
#> 4 term additive + random effectGu & Wahba 4 term additive model
m <- gam(y~s(x0), data=dat) loogam(m)$MAE
#> [1] 3.994149