Defines an X-13ARIMA model to be used inside fabletools::model().
The model is estimated with rjd3x13::jx13() and the Java result is kept in
the fitted model, so that all JDemetra+ indicators can be extracted
afterwards (see jd3_indicator()).
Usage
X13(
formula,
spec = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"),
context = NULL,
ref_spec = spec,
...
)Arguments
- formula
Model formula: the name of the variable to adjust (
y), ory ~ specials(see jd3_specials).- spec
Base specification: a character name (see
rjd3x13::x13_spec()for the available names; the default is the first one) or a specification object fromrjd3x13::x13_spec(). The specials of the formula are applied to it.- context
A modelling context created with
rjd3toolkit::modelling_context()(e.g. for custom calendars), orNULL.- ref_spec
Reference specification stored in the model: it is the reference of the refresh policies used by
refit()andstream(). Defaults tospec, that is the specification before its modification by the specials.- ...
Currently unused.
Value
A model definition that can be passed to fabletools::model(). Once
fitted, the mable column contains a jd3_model object. Use
components() to get the decomposition as a dable
(columns trend, seasonal, irregular and season_adjust).
Details
The specification can be set in two (combinable) ways:
Ex ante, with the
specargument: a name or a specification object created withrjd3x13::x13_spec()and modified with theset_*()functions of rjd3toolkit.In the formula, with specials such as
transform()orxreg()(see jd3_specials). This is the only way to use regressors that are columns of the tsibble.
Specials override the base spec.
Examples
y <- tsibble::as_tsibble(AirPassengers)
# Default specification
mb <- model(y, x13 = X13(value))
components(mb)
#> # A dable: 144 x 7 [1M]
#> # Key: .model [1]
#> # : value = trend * seasonal * irregular
#> .model index value trend seasonal irregular season_adjust
#> <chr> <mth> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 x13 1949 Jan 112 122. 0.920 0.996 122.
#> 2 x13 1949 Feb 118 124. 0.948 1.00 125.
#> 3 x13 1949 Mar 132 126. 1.05 0.994 125.
#> 4 x13 1949 Apr 129 128. 1.00 1.01 129.
#> 5 x13 1949 May 121 128. 0.939 1.01 129.
#> 6 x13 1949 Jun 135 127. 1.07 0.998 127.
#> 7 x13 1949 Jul 148 126. 1.19 0.988 125.
#> 8 x13 1949 Aug 148 126. 1.17 0.999 126.
#> 9 x13 1949 Sep 136 127. 1.07 1.00 128.
#> 10 x13 1949 Oct 119 128. 0.925 1.00 129.
#> # ℹ 134 more rows
# Specification created ex ante with rjd3toolkit
my_spec <- rjd3x13::x13_spec("rsa3")
my_spec <- rjd3toolkit::set_transform(my_spec, fun = "Log")
mb <- model(y, x13 = X13(value, spec = my_spec))
# Specification set in the formula with specials
mb <- model(
y,
x13 = X13(value ~ transform(fun = "Log") +
outlier(outliers.type = c("AO", "LS")))
)
# Regressor taken from a column of the tsibble
y$shock <- as.numeric(y$index == tsibble::yearmonth("1955 Jan"))
mb <- model(y, x13 = X13(value ~ xreg(shock, regeffect = "Series")))
#> Warning: 1 error encountered for x13
#> [1] unused argument (effect = x$regeffect)