Skip to content

Dynamic models using TSLM (ARDL) #423

@defra-ma

Description

@defra-ma

I am trying to estimate an ARDL(p,q). I have used the ARDL package for estimating such models in the past, but would like to use fable's scenario forecasting and bootstrapping tools. ARDL's are just linear models so, lacking a specific ARDL model I should be able to estimate using TSLM.

If I use TSLM I cannot use the order special from AR. While I can estimate a model using dplyr::lag, TSLM doesn't know this is a lag of the dependent variable and so cannot generate a dynamic forecast.

I can estimate any ARDL(p, 0) using AR, but that is only useful when the lag q on the exogenous regressor(s) is zero. The order() special cannot (as far as I know) create lags of an exogenous regressor.

A related issue occurs using scenario, where scenarios featuring lagged regressors created using lag are not recognised.

Is there a way around this without diving into fabletools and creating a new model class (and presumably, fable.ARDL)?

== Edit (28/3):

If one uses I() to wrap any lagged values, e.g. TSLM(y ~ I(lag(y)) + x + I(lag(x)) correctly estimates an ARDL(1,1). The forecast function can then correctly generate the lagged values of x, but then only generates static forecasts as it doesn't know that I(lag(y)) is a lagged dependent variable. However, it seems we can use the order() special from AR which allows us to get a dynamic forecast conditioned on the path(s) of the exogenous variable(s):

library(fable)
library(tsibble)
library(tidyverse)

set.seed(123)
df = tibble(
  time = yearquarter(seq.Date(from = yq("1960-01"), to = yq("1986-04"), by = "quarter")),
  y = as.double(UKgas),
  x = cumprod(c(1, 1 + rnorm(length(y)-1, mean = 0.03, sd = 0.02)))
) %>% 
  as_tsibble(index = time)

train = filter(df, as.Date(time) <= yq("1980-01"))
test = filter(df, as.Date(time) > yq("1980-01")) %>% 
  select(-y)

fit <- train %>% 
  model(
    ar = AR(y ~ order(1) + xreg(I(x)) + xreg(I(lag(x))))
  )

forecast(fit, test) %>% 
  autoplot(train)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions