Skip to contents

Defines a decomposition of a high-frequency series (daily, hourly...) based on an extended (fractional) airline model, to be used inside fabletools::model(). It is estimated with rjd3highfreq::multi_airline_decomposition() (which handles one or several, possibly non-integer, periodicities).

Usage

AIRLINE_DECOMPOSITION(formula, log = FALSE, ...)

Arguments

formula

Model formula: the name of the variable to decompose (y), or y ~ specials (see hf_specials).

log

Multiplicative (TRUE) or additive (FALSE) decomposition. With "auto", the choice is made with rjd3highfreq::loglevel().

...

Other arguments passed to rjd3highfreq::multi_airline_decomposition() (e.g. ndiff, ar, eps, deps).

Value

A model definition that can be passed to fabletools::model(). Once fitted, the mable column contains a hf_model object. Use components() to get the decomposition as a dable.

Details

The series can be pre-adjusted (outliers, holidays, user-defined regressors) with rjd3highfreq::fractional_airline_estimation(): see hf_specials.

Contrary to MSTL(), ISTL(), STLPLUS() and X11PLUS(), this model can be used to forecast and backcast the series (see forecast()).

With log = TRUE, the decomposition is done on the log of the series and the components are exponentiated, so that y = trend * seasonal * irregular (rjd3highfreq::multi_airline_decomposition(log = TRUE) returns additive components in level).

Examples

births <- tsibble::as_tsibble(
  tail(rjd3toolkit::Births, 365 * 4),
  index = date
)

# Daily series: the default periodicities are 7 and 365.25. Only the weekly
# one is used in these examples, which is much faster (see the vignette
# "high-frequency" for the annual periodicity).
mb <- model(births, airline = AIRLINE_DECOMPOSITION(births ~ period(7), log = TRUE))
components(mb)
#> # A dable: 1,460 x 7 [1D]
#> # Key:     .model [1]
#> # :        births = trend * seasonal * irregular
#>    .model  date       births trend seasonal irregular season_adjust
#>    <chr>   <date>      <int> <dbl>    <dbl>     <dbl>         <dbl>
#>  1 airline 2021-01-02   1439 1669.    0.905     0.952         1590.
#>  2 airline 2021-01-03   1427 1672.    0.871     0.980         1639.
#>  3 airline 2021-01-04   1824 1675.    1.01      1.08          1806.
#>  4 airline 2021-01-05   1878 1676.    1.07      1.05          1761.
#>  5 airline 2021-01-06   1820 1673.    1.05      1.03          1727.
#>  6 airline 2021-01-07   1762 1669.    1.05      1.00          1676.
#>  7 airline 2021-01-08   1716 1665.    1.06      0.969         1614.
#>  8 airline 2021-01-09   1434 1662.    0.905     0.953         1584.
#>  9 airline 2021-01-10   1416 1662.    0.871     0.979         1626.
#> 10 airline 2021-01-11   1693 1662.    1.01      1.01          1677.
#> # ℹ 1,450 more rows

# Pre-adjustment: outliers and French holidays
cal <- rjd3toolkit::national_calendar(list(
  rjd3toolkit::special_day("NEWYEAR"),
  rjd3toolkit::special_day("EASTERMONDAY"),
  rjd3toolkit::special_day("MAYDAY"),
  rjd3toolkit::fixed_day(7, 14),
  rjd3toolkit::special_day("CHRISTMAS")
))
mb <- model(
  births,
  airline = AIRLINE_DECOMPOSITION(
    births ~ period(7) + preadjust() + holidays(cal),
    log = TRUE
  )
)
tidy(mb)
#> # A tibble: 7 × 6
#>   .model  term         estimate std.error statistic  p.value
#>   <chr>   <chr>           <dbl>     <dbl>     <dbl>    <dbl>
#> 1 airline theta           0.821   0.0161      50.9  0       
#> 2 airline btheta(7)       0.981   0.00781    126.   0       
#> 3 airline 07-14          -0.123   0.0195      -6.33 2.53e-10
#> 4 airline NEWYEAR        -0.222   0.0338      -6.55 5.82e-11
#> 5 airline EASTERMONDAY   -0.136   0.0170      -8.02 1.09e-15
#> 6 airline MAYDAY         -0.145   0.0239      -6.05 1.44e- 9
#> 7 airline CHRISTMAS      -0.248   0.0240     -10.3  4.38e-25
forecast(mb, h = 14)
#> # A fable: 14 x 4 [1D]
#> # Key:     .model [1]
#>    .model  date         births .mean
#>    <chr>   <date>       <dist> <dbl>
#>  1 airline 2025-01-01  1410.71 1411.
#>  2 airline 2025-01-02   1760.7 1761.
#>  3 airline 2025-01-03 1771.253 1771.
#>  4 airline 2025-01-04 1520.214 1520.
#>  5 airline 2025-01-05 1444.897 1445.
#>  6 airline 2025-01-06 1668.222 1668.
#>  7 airline 2025-01-07 1767.918 1768.
#>  8 airline 2025-01-08 1759.317 1759.
#>  9 airline 2025-01-09  1759.35 1759.
#> 10 airline 2025-01-10 1769.895 1770.
#> 11 airline 2025-01-11 1519.048 1519.
#> 12 airline 2025-01-12 1443.789 1444.
#> 13 airline 2025-01-13 1666.943 1667.
#> 14 airline 2025-01-14 1766.563 1767.