ts_arima: ARIMA

View source: R/ts_arima.R

ts_arimaR Documentation

ARIMA

Description

Create a time series prediction object based on the AutoRegressive Integrated Moving Average (ARIMA) family.

This constructor sets up an S3 time series regressor that leverages the forecast package to either automatically select orders via auto.arima() or fit a user-specified ⁠(p, d, q)⁠ structure, and provide one-step and multi-step forecasts.

Usage

ts_arima(p = NULL, d = NULL, q = NULL)

Arguments

p

Optional integer autoregressive order. Leave NULL to let auto.arima() choose it.

d

Optional integer differencing order. Leave NULL to let auto.arima() choose it.

q

Optional integer moving-average order. Leave NULL to let auto.arima() choose it.

Details

ARIMA models combine autoregressive (AR), differencing (I), and moving average (MA) components to model temporal dependence in a univariate time series. The fit() method uses forecast::auto.arima() to select orders using information criteria when p, d, and q are left as NULL; otherwise it fits the user-specified order directly. predict() supports both a single one-step-ahead over a horizon (rolling) and direct multi-step forecasting.

Assumptions include (after differencing) approximate stationarity and homoskedastic residuals. Always inspect residual diagnostics for adequacy.

Value

A ts_arima object (S3), which inherits from ts_reg.

References

  • G. E. P. Box, G. M. Jenkins, G. C. Reinsel, and G. M. Ljung (2015). Time Series Analysis: Forecasting and Control. Wiley.

  • R. J. Hyndman and Y. Khandakar (2008). Automatic time series forecasting: The forecast package for R. Journal of Statistical Software, 27(3), 1–22. doi:10.18637/jss.v027.i03

Examples

# Example: rolling-origin evaluation with multi-step prediction
# Load package and dataset
library(daltoolbox)
library(tspredit)
data(tsd)

# 1) Wrap the raw vector as `ts_data` without sliding windows
ts <- ts_data(tsd$y, 0)
ts_head(ts, 3)

# 2) Split into train/test using the last 5 observations as test
samp <- ts_sample(ts, test_size = 5)

# 3) Fit a user-specified ARIMA(5,0,0)
model <- ts_arima(p = 5, d = 0, q = 0)
model <- fit(model, x = samp$train)

# 4) Predict 5 steps ahead from the most recent observed point
prediction <- predict(model, x = samp$test[1,], steps_ahead = 5)
prediction <- as.vector(prediction)
output <- as.vector(samp$test)

# 5) Evaluate forecast accuracy
ev_test <- evaluate(model, output, prediction)
ev_test

tspredit documentation built on May 15, 2026, 1:07 a.m.