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])
警告消息: 'newdata' 具有105行,但發現變量具有444行警告在LM預測對於r
順便說一句:長度(test_ind)是105和nrow(火車)= 444
我計劃運行交叉驗證,但上面的代碼會生成警告,我已經在此論壇中跟隨其他帖子做了子集化,然後我進入lm函數,爲什麼還有警告?任何人都可以指出錯誤?謝謝
'rpm'似乎不在'集合中。因此它來自全球環境。 – Roland