我有一堆模型我想通过 GLM 使用,所以我想把它们放在一个列表中,然后循环遍历列表。但是,以下代码会产生错误:
m1<- glm(target~total+tot_eit_h_h1+tot_both_h_h1, data=data, family='binomial')
m2<- glm(target~total+tot_both_h_h1, data=data, family='binomial')
models<- c(m1,m2)
这完美地工作:
predictions <- predict(m1, data, type='response')
此代码得出错误:
predictions <- predict(models[1], data, type='response')
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "list"