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.
Here is an example:
Having to manually
rbindthese results is not ideal (andbind_rowswon'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.