Skip to content

How to handle multiple forecasts from the same model? #110

Description

@robjhyndman

Here is an example:

library(fpp3)
fit <- us_change %>%
  model(lm = TSLM(Consumption ~ Income + Savings + Unemployment))
up_future <- new_data(us_change, 4) %>%
  mutate(Income = 1, Savings = 0.5, Unemployment = 0)
down_future <- new_data(us_change, 4) %>%
  mutate(Income = -1, Savings = -0.5, Unemployment = 0)
fc_up <- forecast(fit, new_data = up_future) %>%
  mutate(Scenario = "Increase") %>% as_fable(response=Consumption, key = Scenario)
fc_down <- forecast(fit, new_data = down_future) %>%
  mutate(Scenario = "Decrease") %>% as_fable(response=Consumption, key = Scenario)

us_change %>%
  autoplot(Consumption) +
  autolayer(rbind(fc_up, fc_down)) +
  ylab("% change in US consumption")

Having to manually rbind these results is not ideal (and bind_rows won't work).

Also, the as_fable() needs the response variable re-specified when it should already have that information. We are just adding a key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions