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)