The model formula will be handled using stats::model.matrix()
, and so
the the same approach to include interactions in stats::lm()
applies when
specifying the formula
. In addition to stats::lm()
, it is possible to
include common_xregs
in the model formula, such as trend()
, season()
,
and fourier()
.
TSLM(formula)
A model specification.
Exogenous regressors can be included in a TSLM model without explicitly using the xreg()
special. Common exogenous regressor specials as specified in common_xregs
can also be used. These regressors are handled using stats::model.frame()
, and so interactions and other functionality behaves similarly to stats::lm()
.
xreg(...)
... | Bare expressions for the exogenous regressors (such as log(x) ) |
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season()))
#> # A mable: 1 x 1
#> lm
#> <model>
#> 1 <TSLM>
library(tsibbledata)
olympic_running %>%
model(TSLM(Time ~ trend())) %>%
interpolate(olympic_running)
#> # A tsibble: 312 x 4 [4Y]
#> # Key: Length, Sex [14]
#> Length Sex Year Time
#> <int> <chr> <int> <dbl>
#> 1 100 men 1896 12
#> 2 100 men 1900 11
#> 3 100 men 1904 11
#> 4 100 men 1908 10.8
#> 5 100 men 1912 10.8
#> 6 100 men 1916 10.8
#> 7 100 men 1920 10.8
#> 8 100 men 1924 10.6
#> 9 100 men 1928 10.8
#> 10 100 men 1932 10.3
#> # ℹ 302 more rows