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 automatically select orders via auto.arima and provide one-step and multi-step forecasts.

Usage

ts_arima()

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, and 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)
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)
io_train <- ts_projection(samp$train)
io_test <- ts_projection(samp$test)

# 3) Fit ARIMA via auto.arima
model <- ts_arima()
model <- fit(model, x = io_train$input, y = io_train$output)

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

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

tspredit documentation built on Feb. 11, 2026, 9:08 a.m.