This function calculates the impulse response function (IRF) of a time series model. The IRF describes how a model's variables react to external shocks over time.
IRF(x, ...)If new_data contains the .impulse column, those values will be
treated as impulses for the calculated impulse responses.
The impulse response function provides insight into the dynamic behaviour of a system in response to external shocks. It traces the effect of a one-unit change in the impulse variable on the response variable over a specified number of periods.
For a mable, the number of periods is specified using h (or by providing
new_data). Model specific options are passed via ..., for example
fable::VAR() models accept impulse (the name of the variable to shock)
and orthogonal (whether to compute orthogonalised impulse responses).
library(fable)
library(tsibble)
#>
#> Attaching package: ‘tsibble’
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, union
# Annual GDP growth and CPI inflation (%) for Australia
aus_economy <- tsibbledata::global_economy %>%
dplyr::filter(Country == "Australia") %>%
dplyr::transmute(Growth, Inflation = 100 * difference(log(CPI))) %>%
dplyr::filter(!is.na(Growth), !is.na(Inflation))
fit <- aus_economy %>%
model(VAR(vars(Growth, Inflation) ~ AR(1)))
# Response of both variables to a unit shock in GDP growth
fit %>%
IRF(h = 10, impulse = "Growth")
#> # A tsibble: 10 x 4 [1Y]
#> # Key: .model [1]
#> .model Year Growth Inflation
#> <chr> <dbl> <dbl> <dbl>
#> 1 VAR(vars(Growth, Inflation) ~ AR(1)) 2018 1 0
#> 2 VAR(vars(Growth, Inflation) ~ AR(1)) 2019 0.219 0.373
#> 3 VAR(vars(Growth, Inflation) ~ AR(1)) 2020 -0.00638 0.415
#> 4 VAR(vars(Growth, Inflation) ~ AR(1)) 2021 -0.0617 0.368
#> 5 VAR(vars(Growth, Inflation) ~ AR(1)) 2022 -0.0670 0.305
#> 6 VAR(vars(Growth, Inflation) ~ AR(1)) 2023 -0.0591 0.248
#> 7 VAR(vars(Growth, Inflation) ~ AR(1)) 2024 -0.0490 0.199
#> 8 VAR(vars(Growth, Inflation) ~ AR(1)) 2025 -0.0397 0.159
#> 9 VAR(vars(Growth, Inflation) ~ AR(1)) 2026 -0.0319 0.127
#> 10 VAR(vars(Growth, Inflation) ~ AR(1)) 2027 -0.0255 0.102
# Orthogonalised response to a shock in inflation
fit %>%
IRF(h = 10, impulse = "Inflation", orthogonal = TRUE)
#> # A tsibble: 10 x 4 [1Y]
#> # Key: .model [1]
#> .model Year Growth Inflation
#> <chr> <dbl> <dbl> <dbl>
#> 1 VAR(vars(Growth, Inflation) ~ AR(1)) 2018 0 1.70
#> 2 VAR(vars(Growth, Inflation) ~ AR(1)) 2019 -0.248 1.52
#> 3 VAR(vars(Growth, Inflation) ~ AR(1)) 2020 -0.275 1.26
#> 4 VAR(vars(Growth, Inflation) ~ AR(1)) 2021 -0.244 1.03
#> 5 VAR(vars(Growth, Inflation) ~ AR(1)) 2022 -0.203 0.825
#> 6 VAR(vars(Growth, Inflation) ~ AR(1)) 2023 -0.164 0.660
#> 7 VAR(vars(Growth, Inflation) ~ AR(1)) 2024 -0.132 0.528
#> 8 VAR(vars(Growth, Inflation) ~ AR(1)) 2025 -0.106 0.422
#> 9 VAR(vars(Growth, Inflation) ~ AR(1)) 2026 -0.0846 0.337
#> 10 VAR(vars(Growth, Inflation) ~ AR(1)) 2027 -0.0676 0.270