collection <- data.frame(col1=X1,col2=X2,col3=X3,col4=X4)
k <- 5
ind <- sample(seq(1,k), length(X1), replace=TRUE)
test_ind = which(ind==1)
train<-collection[-test_ind,]
fit<-lm(X1~poly(X2,2,raw=T)+X3+X4+X2:X3,data=train)
model1_resid<-predict(fit,collection[test_ind,2:4])
Warning message: 'newdata' had 105 rows but variables found have 444 rows
BTW: length(test_ind) is 105 and nrow(train)=444
I plan to run cross validation, but the above code generates the warning, I already followed other posts in this forum to do subsetting before I enter the lm function, why there is still warning? Anyone can point out the bug? Thanks