Last active
January 17, 2016 22:18
-
-
Save michaeldorman/74da31a5d5a6aa629c71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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