[R] How to do cross validation with glm?
Andra Isan
andra_isan at yahoo.com
Wed Aug 24 18:49:10 CEST 2011
Hi All,
I have a fitted model called glm.fit which I used glm and data dat is my data frame
pred= predict(glm.fit, data = dat, type="response")
to predict how it predicts on my whole data but obviously I have to do cross-validation to train the model on one part of my data and predict on the other part. So, I searched for it and I found a function cv.glm which is in package boot. So, I tired to use it as:
cv.glm = (cv.glm(dat, glm.fit, cost, K=nrow(dat))$delta)
but I am not sure how to do the prediction for the hold-out data. Is there any better way for cross-validation to learn a model on training data and test it on test data in R?
Thanks,
Andra
More information about the R-help
mailing list