0
$\begingroup$

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?

$\endgroup$

1 Answer 1

0
$\begingroup$

I've had similar warning issued when:

  1. The number of rows is very low (less than the number of columns) while creating the model.
  2. One of the columns has the same value in all the rows while creating the model.

You can check if either of these two could be the possible reason in this case.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.