I have a large dataset that I need to predict some values for. I have this small reproducible example below. I would like to predict for a few years ahead using either gam or glm, however, I can't wrap my head around it since I don't have statistics background. Could some one guide me on how to predict and add the predicted values to my original dataset?
library(mgcv)
library(tidyverse)
m <- structure(list(year = c(2003, 2003, 2003, 2003, 2003, 2003, 2003,
2003, 2003, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004,
2005, 2005, 2005, 2006, 2006, 2006, 2006, 2006, 2007, 2007, 2007,
2007, 2007), month = c("August", "August", "September", "September",
"October", "October", "November", "November", "December", "August",
"August", "September", "September", "October", "October", "November",
"November", "December", "August", "August", "September", "October",
"October", "November", "November", "December", "August", "August",
"September", "September", "October"), date = structure(c(12265,
12281, 12296, 12311, 12326, 12342, 12357, 12372, 12387, 12631,
12647, 12662, 12677, 12692, 12708, 12723, 12738, 12753, 12996,
13012, 13027, 13422, 13438, 13453, 13468, 13483, 13726, 13742,
13757, 13772, 13787), class = "Date"), turb = c(12.5, 11.8, 8.9,
6.2, 5.1, 3.4, -0.1, 0, -0.1, 12.5, 10.4, 8.6, 6.1, 4.7, 1.4,
0.1, -0.1, -0.1, 12.5, 11, 8, 4.4, 1.1, 0.5, -0.2, -0.2, 12.5,
11.7, 10, 5.9, 3.6)), row.names = c(NA, -31L), class = c("tbl_df",
"tbl", "data.frame"))
m$date <- as.numeric(m$date)
mod1 <- gam(turb ~ s(date), data = m)
summary(mod1)
#How can I predict 3 more years (to 2010) and have those predictions
#added to the bottom of the original dataset(m)?
Perhaps I'm wrong, but I think you're trying to predict
turb
based on the smootheddate
. If so, thenThis can be combined with the original data with