Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic models using TSLM (ARDL) #423

Open
defra-ma opened this issue Feb 28, 2025 · 0 comments
Open

Dynamic models using TSLM (ARDL) #423

defra-ma opened this issue Feb 28, 2025 · 0 comments

Comments

@defra-ma
Copy link

defra-ma commented Feb 28, 2025

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant