I'm working with multiple time series models, and hoping to manage them with data.table:
pkg <- c("data.table", "magrittr", "forecast")
sapply(pkg, library, character.only = TRUE)
df <- data.frame(
group = rep(c("a", "b", "c"), each = 10),
val = sample(1:10, 30, replace = TRUE)
) %>% as.data.table
I can successfully generate the model (and a time series ready for the next step):
t1 <- df[, list(
tsAll = list(val %>% as.ts),
mod1 = list(val %>% as.ts %>% window(1, 7) %>% ets)
), by = group]
I'm now trying to update the ets model, which involves passing 'tsAll' into the ets function and providing the model to use (mod1).
This does not work:
t1[, lapply(tsAll, ets, model = mod1)]
I've also tried:
t1[, lapply(tsAll, ets, model = mod1[[1]])]
This runs, but it looks like the same model is returned to every row.
Possibly I have solved the question but run into this issue:
Why is using update on a lm inside a grouped data.table losing its model data?
Can anyone help with the next step?