Hi there,
I want to create a tibble with all models I will run, and there specification, based on a list of strings that are the column name.
For example, I will use the idea from Forecast: Principles and Practice book: 7.5 Selecting predictors | Forecasting: Principles and Practice (3rd ed)
The idea there was to estimate different combinations of regressor to explain US Consumption.
The output I am looking for is something like it:
tbl_models <- tibble(
model_id = 1:16,
regressors = list(
list(""),
list("Income"),
list("Income", "Production"),
list("Income", "Production", "Savings"),
list("Income", "Production", "Unemployment"),
list("Income", "Production", "Savings", "Unemployment"),
list("Income", "Savings"),
list("Income", "Savings", "Unemployment"),
list("Income", "Unemployment"),
list("Production"),
list("Production", "Savings"),
list("Production", "Unemployment"),
list("Production", "Savings", "Unemployment"),
list("Savings"),
list("Savings", "Unemployment"),
list("Unemployment"))
)
Actually, the column "regressors" should be a list of regressor, only, not like the one above. I am struggling to create this tibble.
Here is my attempt to write a code:
library(tidyverse)
library(fpp3)
list_of_regressores <- us_change[3:6] %>% colnames()
regressors <- map(.x = 1:length(list_of_regressores),
.f = ~ combn(x = list_of_regressores,
m = .x))
tbl_models <- tibble(
model_id = 1:16,
regressors = test
)
Here are the problems:
The variable regressors
is a list of matrices, where each column of each matrix should be a list. And each list should be in a row of tbl_models
.
The column model_id
in tbl_models
should be just a row numbering for the number of models. So, if I increase the number of regressors, it should automatically increase the number 16 to something else.
Any idea?