简体   繁体   中英

How to predict next month given a fitted model?

Say I have fitted a GAM model to the data:

model <- gam(Cases~s(Time, k=5, bs="cs"), data=dengue, family = gaussian(link = indentity))

The data goes up to 32 weeks. How do I predict say the next 4 weeks (33rd to 36th week)?

prediction <- predict(model, se.fit=T, n.ahead=4)

Maybe something like this? Thanks in advance.

You have to provide predict() with a data frame of new data to make the predictions on. See the documentation for details.

In your case this would mean something like:

testdata = data.frame(Time= c(33:36))
prediction <- predict(model, newdata = testdata)

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