我尝试使用以下代码对我的线性回归模型(已经定义为具有最高R2的模型)执行k折验证:
lm.comp7<- lm(Comp~ TA+ EPS+ OC+ TA*EPS+ TA*OC, data=salaries)
cv.err5 <- cv.lm(salaries, lm.comp7,m=5)
attr(cv.err5,'ms')
,我遇到以下错误:
Error in model.frame.default(formula = form, data = data[rows.in, ], drop.unused.levels = TRUE) :
variable lengths differ (found for 'OC')
In addition: Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
我在网上进行了研究,并尝试了以下建议,但效果不佳:
CVlm(数据=薪水,m = 5,form.lm =公式(Comp〜TA + EPS + OC + TA EPS + TA OC))