This function calculates root mean squared error (RMSE) for leave-one-out cross-validation of linear regression estimated via least squares method.
loocv(fit)
Arguments
fit: object of class lm.
Returns
This function returns a numeric value representing root mean squared error (RMSE) of leave-one-out cross-validation (LOOCV).
Details
Fast analytical formula is used.
Examples
set.seed(123)# Generate data according to linear regressionn <-100eps <- rnorm(n)x <- runif(n)y <- x + eps
# Estimate the modelmodel <- lm(y ~ x)# Perform cross-validationloocv(model)