Is there a shorthand in forecasting to abbreviate column names similar to linear models?

13 Views Asked by At

In linear modeling, it's easy to write:

linear1 <- lm(mpg ~ ., data = mtcars)

without having to write all the column names. However I cannot find (nor figure out) anything similar in time series. For example, this fails:

library(fpp3)
head(us_change)
linear1 <- us_change %>% 
  fabletools::model(TSLM(Consumption ~ .,)) %>% 
  report()
Error in TSLM(Consumption ~ ., ) : unused argument (alist())

but this works fine (writing all the column names out):

us_change %>% 
  fabletools::model(TSLM(Consumption ~ Income + Production + Savings + Unemployment)) %>% 
  report()

The data looks like this:

head of US Change data

Is there a shorthand for column names when writing time series models, similar to how linear models can be written?

1

There are 1 best solutions below

0
Russ Conte On

I forgot that I previously asked essentially the same question. It was answered here: Multivariate time series - is there notation to select all the variables, or do they all have to be written out?

As a good example with the current data set:

resp <- "Consumption"
form <- reformulate(response = resp,
                    c(setdiff(names(us_change), resp),
                      "season()", "trend()"))
us_change %>% 
fabletools::model(TSLM(form)) %>% 
  report()

That returns this result (which is the desired result):

Series: Consumption 
Model: TSLM 

Residuals:
     Min       1Q   Median       3Q      Max 
-0.90648 -0.14780 -0.01299  0.13156  1.04526 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)   -2.756442   7.231263  -0.381   0.7035    
Quarter       -0.034715   0.079097  -0.439   0.6612    
Income         0.730331   0.040179  18.177   <2e-16 ***
Production     0.037230   0.023936   1.555   0.1215    
Savings       -0.052284   0.002947 -17.743   <2e-16 ***
Unemployment  -0.226441   0.100480  -2.254   0.0254 *  
season()year2 -0.119831   0.104683  -1.145   0.2538    
season()year3 -0.095053   0.125207  -0.759   0.4487    
season()year4 -0.122601   0.082581  -1.485   0.1393    
trend()        3.168947   7.222511   0.439   0.6613    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3068 on 188 degrees of freedom
Multiple R-squared: 0.7793, Adjusted R-squared: 0.7687
F-statistic: 73.75 on 9 and 188 DF, p-value: < 2.22e-16
>