I am trying to estimate the test error using 10 fold Cross Validation in R. However my code throws a warning and fills my vector of errors with Nans:
#computes the associated 10-fold CV error and stores it in the i-th element of the vector cv.error.10
cv.error.10=rep(0,10)
for (i in 1:10){
cvest=lm(Income ~ . , data = compDAT)
cv.error.10[i]=cv.glm(compDAT,cvest,K=10)$delta[1]
}
cv.error.10
#calculate mean squared error
a_cv_err <- (sum(cv.error.10))/10
I receive the warning:
20: In predict.lm(d.glm, data, type = "response") :
prediction from a rank-deficient fit may be misleading
Which I understand is probably due to a multicollinearity problem within the data. However, I cannot see what error is being thrown causing my vector to be filled with Nans.
I looked up the cv.glm() documentation https://www.rdocumentation.org/packages/boot/versions/1.3-28/topics/cv.glm and I have a suspicion it might be due to the type of model.
Has anyone faced a similar problem?