ARIMA model: identify, fit, check and forecast, with example

Updated

An ARIMA model describes a time series by how each value depends on its own past values and past random shocks. The name lists its three parts: AR, autoregressive terms (past values); I, integration (how many times the series is differenced to make it stationary); and MA, moving average terms (past shocks). A model is written ARIMA(p, d, q) with the order of each part. ARIMA models give forecasts with prediction intervals and describe autocorrelated processes that simple smoothing methods only approximate.

When to use it

  • The series is autocorrelated, as shown by its autocorrelation function, and you want a model of that dependence.
  • You need forecasts with prediction intervals.
  • You want residuals that are close to independent, for example to put on a control chart instead of the autocorrelated raw data.
  • Smoothing methods leave patterns in their errors.

How it works

The usual approach, after Box and Jenkins, has four steps.

1. Identify. Make the series stationary: it should vary around a constant mean with constant spread. A series that wanders or trends is differenced (d = 1 uses yₜ − yₜ₋₁); the augmented Dickey–Fuller test helps decide. Then read the ACF and the partial autocorrelation (PACF) of the stationary series: a PACF that cuts off after lag p suggests AR(p); an ACF that cuts off after lag q suggests MA(q).

2. Estimate. Fit the coefficients. For an AR(1) model with a constant:

yₜ = c + φ·yₜ₋₁ + eₜ mean μ = c / (1 − φ)

Two estimation methods are common: conditional least squares, which conditions on the first observation and minimizes the sum of squared residuals, and exact maximum likelihood, which also uses the first observation. They give close answers in long series. This article uses conditional least squares and shows the maximum likelihood estimates for comparison.

3. Check. The residuals should look like independent noise. Look at their ACF and use the Ljung–Box statistic Q on the residuals, with degrees of freedom equal to the number of lags minus the number of AR and MA coefficients.

4. Forecast. For AR(1), the forecast h steps ahead returns gradually to the mean:

ŷₙ₊ₕ = μ + φʰ·(yₙ − μ) Var(errorₕ) = σ² · (1 + φ² + φ⁴ + … + φ²⁽ʰ⁻¹⁾)

The approximate 95% prediction interval is the forecast ± 1.96 times the square root of that variance. It ignores the uncertainty in the estimated coefficients, so it is slightly too narrow in short series.

Example

This uses the hourly brightener readings from the autocorrelation article: 50 readings (g/L) from a nickel plating bath, mean 3.998, last reading 3.77.

Identify. The series varies around a stable level, and its ACF decays quickly (0.627, 0.343, 0.140), so no differencing is needed (d = 0). The PACF is 0.627 at lag 1 and then small (−0.083, −0.068, 0.012), within ±2/√50 = ±0.283. That points to ARIMA(1, 0, 0) with a constant.

Estimate. Conditional least squares on 49 pairs:

TermCoefficientSEtp
Constant1.3500.4483.010.004
AR(1) φ0.6610.1125.90< 0.001

The mean is 1.350 / (1 − 0.661) = 3.979 g/L. The residual mean square is 0.01275 with 47 degrees of freedom, so σ̂ = 0.113 g/L. Exact maximum likelihood gives μ = 3.995, φ = 0.662 and σ = 0.111, nearly the same. As a check against an under-fitted model, an AR(2) term adds a coefficient of −0.110 with a standard error of 0.147 (t = −0.75), so it is not needed.

Check. The residual autocorrelations at lags 1 to 6 are 0.096, −0.010, −0.117, −0.054, −0.056 and −0.082, all well within ±2/√49 = ±0.286.

Residual autocorrelation of the AR(1) model-0.2-0.10.00.10.2Autocorrelation123456789101112
Residual autocorrelation of the AR(1) model
LagsQdfp-value
61.9650.855
1210.66110.472
1812.85170.746

No evidence of remaining autocorrelation: the model captures the dependence.

Forecast. The last reading, 3.77, is below the mean, so the forecasts climb back toward 3.979. For one hour ahead: 3.979 + 0.661 × (3.77 − 3.979) = 3.841.

AR(1) forecasts of brightener concentration with 95% limits3.63.84.04.2Brightener (g/L)ForecastLower 95% limitUpper 95% limit515253545556Hour
AR(1) forecasts of brightener concentration with 95% limits

The interval widens from ±0.22 g/L one hour ahead to about ±0.29 g/L six hours ahead, approaching the spread of the process itself. The residuals, with σ̂ = 0.113 g/L, can now go on an individuals chart: they are close to independent, so the chart's limits will be valid where limits on the raw readings were too narrow.

How to read the results

  • Coefficients and their p-values show which terms matter. A coefficient whose interval includes 0 is usually dropped.
  • φ measures persistence. Near 0, shocks vanish within one period; near 1, they linger and the series behaves almost like a random walk.
  • The residual Ljung–Box p-values should be large. Small values mean the model misses some dependence.
  • Forecast intervals grow with the horizon. For a stationary model they level off at the process spread; for a differenced model they keep growing.

Common mistakes

  • Fitting ARIMA to a non-stationary series without differencing. The AR coefficient lands near 1 and forecasts and intervals are misleading.
  • Over-differencing. Differencing a stationary series creates an artificial MA pattern; check whether d = 1 is really needed.
  • Adding terms until everything is significant. Prefer the simplest model whose residuals pass the checks, or compare candidates by AIC or BIC, as in forecast with best ARIMA.
  • Using short series. ARIMA needs about 50 observations or more; with fewer, the ACF and PACF are too noisy to identify the order.

Frequently asked questions

What do p, d and q mean?

p is the number of autoregressive terms (past values), d is the number of differences, and q is the number of moving average terms (past shocks). ARIMA(1, 0, 0) is a plain AR(1) model; ARIMA(0, 1, 1) is the model behind single exponential smoothing.

Should the model include a constant?

For d = 0, the constant sets the mean and is usually needed. For d = 1, a constant means a steady drift up or down; include it only if the differenced series has a nonzero mean.

Conditional least squares or maximum likelihood?

Both are standard. Maximum likelihood uses all observations and is preferred for short series or MA terms; conditional least squares is simpler. Here they differ by less than 0.02 g/L in the mean.

Can ARIMA handle seasonal data?

Yes, with seasonal terms at the seasonal lag (for example lag 12 in monthly data), written ARIMA(p, d, q)(P, D, Q)ₛ. Identification follows the same steps at the seasonal lags.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab