I am trying to reproduce the example of table 7.1 from https://otexts.com/fpp3/selecting-predictors.html.
The idea of the code was something like this:
library(fpp3)
library(purrr)
library(fable)
library(fabletools)
list_of_regressor <- colnames(us_change)[3:6]
list_of_models <- map(1:length(list_of_regressor), ~ combn(list_of_regressor, .x) %>%
apply(., 2, function(v) paste0("Consumption", " ~ ", paste(v, collapse = " + ")))) %>%
unlist()
models <- us_change %>%
model(
TSLM(list_of_models)
)
models %>% glance() %>% select(.model, adj_r_squared, CV, AIC, AICc, BIC)
I also tried different ways:
# Try #2
list_of_models2 <- map(1:length(list_of_regressor), ~ combn(list_of_regressor, .x) %>%
apply(., 2, function(v) as.formula(paste0("Consumption", " ~ ", paste(v, collapse = " + "))))) %>%
unlist()
models <- us_change %>%
model(
map(.x = list_of_models2, .f = function(x) TSLM(x))
)
# Try #3
list_of_models3 <- map(1:length(list_of_regressor), ~ combn(list_of_regressor, .x) %>%
apply(., 2, function(v) (paste0("TSLM(Consumption", " ~ ", paste(v, collapse = " + ", ")"))))) %>%
unlist()
models <- us_change %>%
do.call(model, TSLM(list_of_models2))
I looked on internet, but I haven't found anything. So, any help will be appreciated.