Fit an AR(p) autoregressive model with a Bayesian MCMC analysis and return the posterior
forecast curve, credible band, and goodness-of-fit scalars. Wraps the shared C++ ARAnalysis.
Usage
ar_analysis(
data,
order_p = 1L,
include_intercept = TRUE,
training_time_steps = NULL,
forecasting_time_steps = 0L,
sampler = "DEMCz",
iterations = 3000L,
output_length = 10000L,
credible_level = 0.9,
seed = 12345L,
thinning_interval = -1L
)Arguments
- data
numeric vector of the observed time series (in sequence order).
- order_p
autoregressive order (default
1).- include_intercept
logical; include an intercept term (default
TRUE).- training_time_steps
number of leading steps used for calibration; when
NULLthe model default (max(30, floor(0.8 * n))) is used, which is invalid for short series – set it explicitly (e.g.15) whennis small.- forecasting_time_steps
number of steps to forecast past the observed series (default
0).- sampler
MCMC sampler:
"DEMCz"(default),"DEMCzs","ARWMH", or"NUTS".- iterations
number of post-warmup MCMC iterations.
- output_length
number of posterior samples used to build the credible band.
- credible_level
credible-interval width (e.g.
0.90for a 90% band).- seed
PRNG seed for the sampler (fixed for reproducibility).
- thinning_interval
MCMC thinning interval;
-1(default) keeps the sampler's own default.
Value
A named list: parameters (posterior point estimate), mode_curve, mean_curve,
lower_ci, upper_ci (the forecast + credible band over the observed range plus the forecast
horizon), and the scalars aic, bic, dic, rmse.
Examples
x <- c(10.2, 11.5, 9.8, 12.1, 13.4, 11.9, 10.6, 12.8, 14.0, 13.1, 11.7, 12.5, 13.9, 15.2,
14.1, 12.9, 13.6, 15.0, 16.2, 14.8)
fit <- ar_analysis(x, order_p = 1, training_time_steps = 15, forecasting_time_steps = 3,
iterations = 100, output_length = 200, seed = 12345, thinning_interval = 1)
length(fit$mode_curve)
#> [1] 23