我刚开始使用speedglm
包。我拟合了一个非常简单的模型并尝试预测响应变量(yhat
)。
library(speedglm)
data<-data.table(x=1:10, y=5:14)
model<-speedlm(y~x, data=data)
与lm函数相比,我无法使用predict(model)
来获取yhat
。我可以为speedglm
包使用任何相应的例程吗?
答案 0 :(得分:2)
据我所知,没有predict
方法。你牺牲速度的便利性。但是,计算yhat值非常容易:
data[, yhat := c(cbind(1, x) %*% coef(model))]
# x y yhat
# 1: 1 5 5
# 2: 2 6 6
# 3: 3 7 7
# 4: 4 8 8
# 5: 5 9 9
# 6: 6 10 10
# 7: 7 11 11
# 8: 8 12 12
# 9: 9 13 13
#10: 10 14 14