function(lm.object) { # Computes the cross-validation (CV), the generalized cross-validation (GCV) and the cross-validation correlation coefficient (R^2_{CV}) for the specified linear model res <- lm.object$residuals y <- lm.object$fitted.values + lm.object$residuals h <- lm.influence(lm.object)$hat n <- length(y) cv <- mean(res^2/(1 - h)^2) gcv <- (n * sum(res^2))/lm.object$df^2 r2cv <- cor(y, y - res/(1 - h))^2 return(cbind(cv, gcv, r2cv)) }