Takes an ARIMA term as defined by arima() and returns
the metadata required to wire the term into a Stan model. Unlike
construct_rw(), this does not modify the data or produce design
matrix columns; ARIMA latent residuals enter the linear predictor
through a parameter-dependent kernel applied to unit-normal shocks
(see inst/stan/functions/arima_kernel.stan).
Arguments
- arima
An ARIMA term as defined by
arima().- data
A
data.frameof observations used to define the ARIMA term. Must contain the time and (if specified) grouping variable.
Value
A list with the following elements:
time,by,p,d,q: passed through from thearima()term.T: number of distinct time points in the series.G: number of groups (1 ifbyis unspecified).time_idx: integer vector mapping each row ofdatato a time index in1:T.group_idx: integer vector mapping each row ofdatato a group index in1:G.time_vals,group_levels: lookup vectors so the indices can be inverted.name: a label for the term, suitable as a parameter prefix.
See also
Functions used to help convert formulas into model designs
ar(),
arima(),
arima_terms(),
arma(),
as_string_formula(),
construct_gp(),
construct_re(),
construct_rw(),
enw_formula(),
enw_manual_formula(),
gp(),
gp_terms(),
ma(),
parse_formula(),
re(),
remove_arima_terms(),
remove_gp_terms(),
remove_rw_terms(),
rw(),
rw_terms(),
split_formula_to_terms()
Examples
data <- enw_example("preproc")$metareference[[1]]
epinowcast:::construct_arima(arima(week), data)
#> $time
#> [1] "week"
#>
#> $by
#> NULL
#>
#> $p
#> [1] 1
#>
#> $d
#> [1] 0
#>
#> $q
#> [1] 0
#>
#> $T
#> [1] 6
#>
#> $G
#> [1] 1
#>
#> $time_idx
#> [1] 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 6 6 6
#> [39] 6 6
#>
#> $group_idx
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> [39] 1 1
#>
#> $time_vals
#> [1] 0 1 2 3 4 5
#>
#> $group_levels
#> [1] "1"
#>
#> $name
#> [1] "arima__week"
#>
epinowcast:::construct_arima(
arima(week, day_of_week, p = 2, d = 1), data
)
#> $time
#> [1] "week"
#>
#> $by
#> [1] "day_of_week"
#>
#> $p
#> [1] 2
#>
#> $d
#> [1] 1
#>
#> $q
#> [1] 0
#>
#> $T
#> [1] 6
#>
#> $G
#> [1] 7
#>
#> $time_idx
#> [1] 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 6 6 6
#> [39] 6 6
#>
#> $group_idx
#> [1] 7 5 1 3 4 2 6 7 5 1 3 4 2 6 7 5 1 3 4 2 6 7 5 1 3 4 2 6 7 5 1 3 4 2 6 7 5 1
#> [39] 3 4
#>
#> $time_vals
#> [1] 0 1 2 3 4 5
#>
#> $group_levels
#> [1] "Friday" "Monday" "Saturday" "Sunday" "Thursday" "Tuesday"
#> [7] "Wednesday"
#>
#> $name
#> [1] "arima__week__day_of_week"
#>
