This may be a silly question but I just can't find a package to do that...I know I can write some codes to get what I want but it would be nice to have a function to do it automatically!
So basically I want to do a k-fold cross-validation for a glm model. I want to automatically get the predictions of each validation set and the actual value too. So if I am doing a 10-fold CV, I want a function to return the 10 validation sets with the actual responses and predictions all together.
Thank you in advance!
I would suggest investigating
cv.glm
from packageboot
, because you are working with a glm model. Another option would be packagecvTools
. I've found it more useful to write up my own function for CV, though. It sounds like you want a CV function that ends halfway, and most CV functions I've seen will average the prediction error over all the validation sets and return just the average (which, of course, is the definition of cross validation).As stated in the comments,
caret
makes cross-validation very easy. Just use the "glm" method, like so: