I have two vectors of simulated data as follows:
x = rnorm(1000, mean = 0, sd = 1)
eps = rnorm(1000, mean = 0, sd = sqrt(0.25))
I am trying to use boot library's glm
and cv.glm
function to fit a linear regression model and multiple linear regression model with either leave one out cross-validation or k-fold cross-validation. The piece of code that I am using with the error I am getting is as follows:
> glm.fit=glm(y~x)
> cv.err=cv.glm(x, glm.fit)
Error in if ((K > n) || (K <= 1)) stop("'K' outside allowable range") :
missing value where TRUE/FALSE needed
I did check using is.na(x)
and confirmed that there are no null values present. Could anyone please suggest a solution for this or point out what am I doing wrong?
Thanks in advance.