Skip to content

Instantly share code, notes, and snippets.

@michaeldorman

michaeldorman/loocv_lm.R

Last active Jan 17, 2016
Embed
What would you like to do?
loocv = function(formula, data) {
pred = rep(NA, nrow(data))
for(i in 1:nrow(data)) {
fit = lm(formula = formula, data = data[-i, ])
pred[i] = predict(fit, data[i, ])
}
data.frame(obs = data[, all.vars(formula)[1]], pred = pred)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment