powered by
This function calculates root mean squared error (RMSE) for leave-one-out cross-validation of linear regression estimated via least squares method.
loocv(fit)
This function returns a numeric value representing root mean squared error (RMSE) of leave-one-out cross-validation (LOOCV).
object of class lm.
lm
Fast analytical formula is used.
set.seed(123) # Generate data according to linear regression n <- 100 eps <- rnorm(n) x <- runif(n) y <- x + eps # Estimate the model model <- lm(y ~ x) # Perform cross-validation loocv(model)
Run the code above in your browser using DataLab