简体   繁体   中英

How to predict the response variable of a speedlm model in R?

I have just started using the speedglm package. I fitted a very simple model and tried to predict the response variable ( yhat ).

library(speedglm)

data<-data.table(x=1:10, y=5:14)

model<-speedlm(y~x, data=data)

In contrast to the lm function I cannot use the predict(model) to get the yhat . Is there any respective routine I can use for the speedglm package?

As far as I can see there is no predict method. You sacrifice convenience for speed. However, it's quite easy to calculate the yhat values:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM