tidyverts / tidyverts/fable

Dynamic models using TSLM (ARDL)

Open
#423 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
588
Forks
71
Avg merge
1h 58m
Merged PRs (30d)
1

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ARDL examples using TSLM, AR, xreg(), lag(), order(), and scenario() in the issue body, then read the relevant fabletools model and forecasting behavior. Done means dynamic forecasts and scenario forecasts correctly recognize lagged dependent and exogenous variables without requiring a new model class.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
analytics, data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.