A model that ignores autocorrelation (the link between a value and past values) may miss time patterns when such a link is there. A simple moving average on correlated data can give intervals that are too narrow and predictions that lag.

ARIMA (AutoRegressive Integrated Moving Average) models autocorrelation. It tends to work best when the series is stationary (or can be made stationary), there are enough observations for the terms you choose, and the underlying process is roughly linear. Miss these and ARIMA can give precise-looking forecasts that are systematically wrong.

This example uses made-up weekly data. It tests an AR(1) model against a forecast that repeats the last value, on held-out data.

This isn't a randomized experiment. It's time series analysis. We can't control the treatment. But we can check the model properly: fit on the earlier part of the series, test on the later part, and measure forecast accuracy on data the model has never seen. If it fails out-of-sample, the forecasts should not be trusted.

Worked Example (Simulated): AR(1) Model or Repeat the Last Value?

Question: On made-up weekly data, does an AR(1) model (one that uses the last value) beat a guess that repeats the last value?

Inputs: Simulated data, seed 136. The script makes 180 values with a set mean of 100, a set lag effect of 0.75 (the pull from the prior value), and random noise with standard deviation 5. It fits the model on the first 140 values and checks the last 40.

Method: Fit the AR(1) terms with least squares. Make a step by step forecast for the test set, each step using the one before. Compare its mean absolute error (MAE, the mean size of each miss) and root mean square error (RMSE, a score that weighs big misses more) with a guess that repeats the last training value.

import numpy as np

# Simulated data, seed 136. The AR(1) form, mean, phi and noise are set here.
rng = np.random.default_rng(136)
n = 180
mu = 100.0
phi = 0.75
noise_sd = 5.0
x = np.empty(n)
x[0] = mu
for t in range(1, n):
    x[t] = mu + phi * (x[t - 1] - mu) + rng.normal(0.0, noise_sd)

train_n = 140
train = x[:train_n]
test = x[train_n:]
y = train[1:]
lag = train[:-1]
design = np.column_stack((np.ones(len(lag)), lag))
intercept, slope = np.linalg.lstsq(design, y, rcond=None)[0]

forecast = np.empty(len(test))
value = train[-1]
for i in range(len(test)):
    value = intercept + slope * value
    forecast[i] = value
baseline = np.full(len(test), train[-1])

mae = np.mean(np.abs(forecast - test))
rmse = np.sqrt(np.mean((forecast - test) ** 2))
base_mae = np.mean(np.abs(baseline - test))
base_rmse = np.sqrt(np.mean((baseline - test) ** 2))
forecast4 = forecast[3]
forecast8 = forecast[7]

print("Simulated data, seed 136")
print(f"Inputs: {n} weekly values; train={train_n}; test={len(test)}; "
      f"set AR(1) mean={mu:.2f}, phi={phi:.2f}, noise SD={noise_sd:.2f}")
print(f"Fit on train: x[t] = {intercept:.4f} + {slope:.4f} x[t-1]")
print(f"Forecast from final train value: week +4={forecast4:.2f}; "
      f"week +8={forecast8:.2f}")
print(f"Recursive test forecast errors: MAE={mae:.2f}; RMSE={rmse:.2f}")
print(f"Baseline (last train value) errors: MAE={base_mae:.2f}; "
      f"RMSE={base_rmse:.2f}")

Printed output:

Simulated data, seed 136
Inputs: 180 weekly values; train=140; test=40; set AR(1) mean=100.00, phi=0.75, noise SD=5.00
Fit on train: x[t] = 27.1410 + 0.7282 x[t-1]
Forecast from final train value: week +4=100.42; week +8=100.03
Recursive test forecast errors: MAE=7.34; RMSE=8.98
Baseline (last train value) errors: MAE=7.71; RMSE=9.56

Result: The series was built as an AR(1) series, the same form as the model, so it wins here by design, and the gap is small (MAE 7.34 against 7.71, RMSE 8.98 against 9.56). The forecast four and eight weeks ahead (100.42, 100.03) has already come back to the long-run mean of about 100, which is why it does little better than repeating the last value.

Limit: This is one made-up series with a set AR(1) pattern, and the model is AR(1), not a full ARIMA. It does not show how the model works on real shop data.

Sources

  • Hyndman R, Athanasopoulos G, Forecasting: Principles and Practice (3rd ed.), otexts.com/fpp3. A general reference for ARIMA modeling.
  • Dickey D, Fuller W (1979), doi 10.1080/01621459.1979.10482531. Cited only for who published the unit-root test and when.

Three Conditions to Check Before Fitting ARIMA

Before you fit an ARIMA model, check these three conditions. If any fail, your forecasts may be unreliable regardless of how well the model fits your training data.

To see where your own measure is heading, with a likely range, try the free forecasting tool.

Condition 1: Stationarity (or transformable to stationary). The series must have constant mean, constant variance, and autocorrelation that depends only on lag, not on time. Plot your data. If you see a trend, up or down, it's not stationary. If the variance increases over time, wider swings in later periods, it's not stationary. If the average level shifts between periods, it's not stationary.

Most business data fails this test initially. That's fine. The "I" in ARIMA stands for "Integrated," which means we difference the data, subtract each value from the previous one, until it becomes stationary. First differencing removes linear trends. Second differencing (rare) removes quadratic trends. If you need more than d=2, ARIMA may be the wrong method.

Condition 2: Sufficient observations. The data you need depends on how noisy the series is and how many terms the model has. A longer series gives a steadier fit. For seasonal ARIMA (SARIMA, a model for repeating time patterns), the data you need depends on the number of full cycles and the size of the model.

Condition 3: Linear autocorrelation structure. ARIMA assumes the relationship between past and future is linear. If your series has regime changes, periods where the process fundamentally shifts, ARIMA will average across regimes and fail in both. If you have threshold effects (price only responds once inventory drops below X), ARIMA will miss the nonlinearity.

Experimental Design Note: ARIMA is a descriptive model, not a causal one. It tells you how the past predicts the future, not why. If you intervene (change pricing strategy, launch a promotion, shift suppliers) the model may break. Always test on out-of-sample data and retrain when the underlying process changes.

How ARIMA Decomposes Time Series Into Components

ARIMA combines three components: AutoRegressive (AR), Moving Average (MA), and differencing (I). Understanding what each component does helps you interpret the model and diagnose failures.

AutoRegressive (AR) component: The AR(p) part says today's value is a linear combination of the past p values plus noise. AR(1) means today depends on yesterday. AR(2) means today depends on yesterday and the day before. The ACF (autocorrelation function) plot shows you how strong these dependencies are at different lags.

If your PACF (partial autocorrelation) plot cuts off sharply after lag p, you probably need an AR(p) model. Retail sales may show AR(1) structure. This week's sales predict next week's sales because customer behavior persists. But if the PACF decays gradually without a clear cutoff, pure AR won't work.

Moving Average (MA) component: The MA(q) part says today's value depends on today's shock plus the past q shocks. This captures situations where random events have lingering effects. A supply disruption doesn't just affect this week. It propagates forward for q weeks until the system adjusts.

If your ACF plot cuts off sharply after lag q while the PACF decays gradually, you need an MA(q) model. Some economic series show MA structure because shocks (weather, policy changes, stockouts) have temporary but multi-period effects.

Integrated (I) component: The I(d) part differences the series d times to achieve stationarity. d=0 means the series is already stationary. d=1 means you difference once (subtract each value from the previous). d=2 means you difference twice (rare in practice).

Here's how to determine d: plot your series. If it has a trend, try d=1. Plot the differenced series. If it still has a trend or the variance is growing, try d=2. If d=2 doesn't produce a stationary series, ARIMA may be the wrong tool. You may have regime changes or nonlinearity.

Parameter Selection Protocol: Don't guess p, d, q. Use a unit-root test, such as the Augmented Dickey-Fuller test (Dickey and Fuller, 1979), to help choose d. Plot the links between a value and past values (ACF and PACF plots) to narrow down p and q. Then fit candidate models and compare them with scores that weigh fit against size, and with tests on held-out data.

Adding a Second Series (ARIMAX)

Sometimes a second series, such as sales volume, moves with the series you forecast. ARIMA treats the target as a univariate series. To bring in a second series, you would need ARIMAX (ARIMA with exogenous variables) or a VAR (Vector AutoRegression) model that jointly forecasts both series.

Here's the design choice: should we build a univariate ARIMA on the target alone, or a multivariate model that uses the second series? The univariate model is simpler and requires fewer assumptions. The multivariate model could be more accurate but requires that the second series is (a) easier to forecast than the target, and (b) the relationship between them is stable. If the relationship changes over time (consumer preferences shift, substitution to other products varies) the multivariate model will fail.

The practical answer: start univariate. Fit an ARIMA model, test it on held-out data, and measure MAPE (mean error as a percent). Then build ARIMAX with the second series as an exogenous variable. If out-of-sample MAPE improves, weigh the gain against the added complexity. A simpler univariate model is easier to maintain.

Fitting ARIMA: The Parameter Selection Protocol

Now we get to the actual modeling. Don't skip this section. Most ARIMA failures come from wrong parameter selection, not from ARIMA being the wrong method.

Step 1: Test for stationarity. Run the Augmented Dickey-Fuller test. Null hypothesis: the series has a unit root (non-stationary). If p < 0.05, reject the null. The series is stationary. If p > 0.05, you need differencing. Try d=1 (first difference) and retest. Keep differencing until ADF p-value < 0.05.

If a series looks stationary on the plot (mean-reverting around a steady level), we'd likely find d=0. But don't trust your eyes: run the test. If the ADF test suggests d=1, consider d=1 even if the plot looks stationary. The test gives a second check beyond the eye.

Step 2: Plot ACF and PACF. ACF (autocorrelation function) shows correlation between the series and its lagged values. PACF (partial autocorrelation) shows correlation at each lag after removing the effect of shorter lags. These plots tell you the order of AR and MA components.

Decision rules: If PACF cuts off sharply after lag p (values become insignificant) and ACF decays gradually, use AR(p). If ACF cuts off after lag q and PACF decays, use MA(q). If both decay gradually, use both AR and MA: start with ARIMA(1,d,1) and expand if needed.

For weekly data, you might see significant autocorrelation at lag 1 (this week predicts next week) and possibly lags 2-4 (if shocks persist). If the ACF shows a spike at lag 52 (one year), that's seasonal autocorrelation. You need SARIMA, not plain ARIMA.

Step 3: Fit candidate models and compare AIC/BIC. Based on ACF/PACF, select a few candidate models. For example: ARIMA(1,0,0), ARIMA(0,0,1), ARIMA(1,0,1), ARIMA(2,0,1), ARIMA(1,0,2). Fit each model to your training data (the earlier part of the series) and record AIC and BIC.

AIC (Akaike Information Criterion) and BIC (Bayesian Information Criterion) balance model fit against complexity. Lower is better. BIC penalizes complexity more than AIC, so if they disagree, BIC will prefer the simpler model.

Step 4: Check residuals. Fit your chosen model and extract residuals. Plot them. They should look like white noise: no pattern, no autocorrelation, roughly normal distribution. Run the Ljung-Box test: if p > 0.05, residuals are uncorrelated (good). If p < 0.05, the model hasn't captured all the autocorrelation: try a higher-order model.

Also check residual normality with a Q-Q plot. If residuals have fat tails or skew, your forecast intervals will be wrong even if point forecasts are accurate. This doesn't rule out the model, but it means you should widen confidence intervals or use bootstrapped intervals instead of assuming normality.

Common Mistake: Selecting parameters by minimizing in-sample error. This tends to cause overfitting. Always test on out-of-sample data: hold out the last part of your series, fit on the rest, and measure MAPE or RMSE on the holdout set. The model with the lowest out-of-sample error is the better choice for forecasting, even if it has higher AIC than alternatives.

Forecasting Forward: Confidence Intervals and Forecast Horizon

Once you have fit and checked the model, you can generate forecasts. But forecast accuracy usually degrades as you extend the horizon, and the confidence intervals you get from the model can be too narrow.

Forecast horizon limits: ARIMA forecasts revert to the mean. If you forecast 1 week ahead, the model uses actual data from this week. If you forecast 10 weeks ahead, the model uses its own predictions from weeks 2-9, compounding errors. As the horizon grows, a stationary ARIMA forecast moves toward the series mean and the uncertainty widens. The simulated example above shows this.

Far-ahead point estimates may sit close to the mean and say little. Check whether the uncertainty at your horizon is small enough for the decision.

Confidence intervals are usually too narrow: The default intervals assume your model is correct and errors are normally distributed. Both assumptions can fail. Your model is an approximation, and real-world shocks are fatter-tailed than Gaussian.

Fix this by bootstrapping: simulate 1,000 forecast paths by resampling residuals, then take the 2.5th and 97.5th percentiles as your 95% interval. These bootstrap intervals can be wider and more realistic than the default analytical intervals.

Testing on holdout data: After fitting on the earlier part of the series, forecast the held-out part. Calculate MAPE (Mean Absolute Percentage Error) and RMSE (Root Mean Squared Error) on the holdout predictions. Judge the errors against what the decision needs: how large a miss can you accept? If the errors are too large for that, consider alternative methods or incorporate more data.

Working on this for your business? See the time series forecasting tool.

When ARIMA Fails: Three Red Flags

ARIMA isn't always the right tool. Here are three situations where it will fail, and what to use instead.

Red Flag 1: Regime changes. If the underlying process shifts (new competitor enters, pricing strategy changes, supply chain restructures) ARIMA will average across regimes and fail in both. The model assumes the past predicts the future through a stable relationship. When that relationship breaks, forecasts break.

How to detect: Plot residuals over time. If you see clusters of large errors in specific periods (not randomly distributed), you have regime changes. Also check if forecast errors increase suddenly at a specific date. That's when the regime changed.

What to do instead: Use piecewise ARIMA (fit separate models before/after the regime change), or switch to a method that handles structural breaks, like state-space models or Bayesian structural time series.

Red Flag 2: Strong seasonality with limited data. SARIMA can handle seasonality, but it needs several full seasonal cycles. With only one cycle of data, SARIMA may overfit. It doesn't have enough cycles to distinguish true seasonal patterns from noise.

How to detect: Fit SARIMA and check if seasonal parameters are statistically significant (p-values < 0.05). If they're not, you don't have enough data. Also check out-of-sample MAPE, if it's worse than a simple seasonal naive forecast (same month last year), SARIMA may be overfitting.

What to do instead: Use seasonal decomposition (STL) to remove seasonality, then fit ARIMA on the deseasonalized series. Or use a method designed for short time series with seasonality, like Prophet or exponential smoothing with seasonal components.

Red Flag 3: Heteroskedasticity (changing variance). If variance increases over time, later periods have bigger swings than earlier periods, ARIMA will underestimate uncertainty in recent data and overestimate it in older data. The forecast intervals will be wrong.

How to detect: Plot residuals squared over time. If you see an upward trend, variance is increasing. Also run the ARCH test (Autoregressive Conditional Heteroskedasticity), if p < 0.05, you have time-varying variance.

What to do instead: Use GARCH (Generalized ARCH) models, which explicitly model time-varying variance. Or log-transform your series to stabilize variance, then fit ARIMA on the logged data. Just remember to back-transform forecasts (exponentiate) and adjust for bias when you do.

ARIMA vs Prophet vs Exponential Smoothing: Which Forecasting Method?

ARIMA isn't the only time series forecasting method. Here's when to use it versus alternatives.

Use ARIMA when: You have enough observations, the series is stationary or can be made stationary, and you need to understand the autocorrelation structure. ARIMA is also good when you want interpretable parameters: the AR and MA coefficients tell you how the process works, not just what it predicts.

Use Prophet when: You have strong seasonality, trend changes (growth rate shifts), and holiday effects. Prophet is built for series like these and can model more than one seasonal pattern. Its components are less direct to read than ARIMA coefficients.

Use Exponential Smoothing when: You want simplicity and your data has trend and/or seasonality but you don't care about autocorrelation structure. ETS (Error-Trend-Seasonal) models are easier to fit and explain to non-technical stakeholders. They may not handle complex autocorrelation patterns as well.

ARIMA fits when the series appears stationary, there is enough data, and you want to understand the autocorrelation (how long shocks persist). If the data showed strong yearly seasonality (say, consistent spikes every January), consider Prophet. If you needed a quick, simple model for stakeholder review, start with ETS.

How to Interpret Your ARIMA Results

You've fit the model, tested it on holdout data, and generated forecasts. Now you need to communicate the results. Here's how to interpret and present ARIMA output.

Parameter interpretation: If your best model is ARIMA(1,1,1), that means one AR term, first differencing, and one MA term. The AR coefficient (φ₁) tells you how much today's differenced value depends on yesterday's differenced value. If φ₁ = 0.6, a shock keeps 60% of its size at each step.

The MA coefficient (θ₁) tells you how shocks propagate. If θ₁ = -0.4, a positive shock this week creates a negative correction next week (mean reversion). This is common in prices: a supply shortage spikes prices, then increased supply the following week pushes them back down.

Forecast communication: Always present forecasts with confidence intervals. Don't just say "we forecast 120 next week." Say "we forecast 120 with 95% confidence interval [105, 135]." (Made-up figures.) The width of that interval tells decision-makers how certain the forecast is.

Also report out-of-sample accuracy: "This model achieved 9% MAPE on the holdout set." That gives stakeholders a sense of reliability. If they need accuracy within ±5%, and your model delivers ±9%, they know to use it cautiously or request more data.

Residual diagnostics: Show the Ljung-Box test result and residual plot. If p > 0.05 and residuals look like white noise, the model has captured the structure well. If p < 0.05, there's remaining autocorrelation: either the model is misspecified or there are external factors the model can't capture.

If residuals show a pattern (e.g., large errors clustered in specific months), explain it. "The model struggles during Q4, likely due to holiday demand shifts that aren't captured by the autocorrelation structure. Consider adding seasonal indicators for Nov-Dec."

Your turn

Bring your own data and the question you actually need answered.

MCP AnalyticsData science by email Send us your data and your question, and we will reply. ds@mcpanalytics.ai

Frequently Asked Questions

When should I use ARIMA instead of simpler forecasting methods?

Use ARIMA when your time series shows autocorrelation, when past values predict future values through a systematic pattern. Simple methods like moving averages ignore this dependency structure. ARIMA tends to work best when the series is stationary (or can be made stationary through differencing), there are enough observations for the terms you choose, and you need to understand the underlying process, not just get predictions.

What does stationarity mean and why does ARIMA require it?

A stationary series has constant mean, variance, and autocorrelation over time. ARIMA requires stationarity because the model parameters assume these properties don't change. If your series has a trend or changing variance, ARIMA may produce unreliable forecasts. The "I" in ARIMA (Integrated) handles this by differencing the data, subtracting each value from the previous one, until the series becomes stationary.

How do I choose the right p, d, q parameters for ARIMA?

Start with d: difference the series until it's stationary (usually d=0, 1, or 2). Then use ACF and PACF plots: if ACF cuts off sharply and PACF decays gradually, use MA (q parameter); if PACF cuts off and ACF decays, use AR (p parameter); if both decay gradually, use both. Compare candidates with AIC/BIC scores and with out-of-sample testing, and do not trust the model until you have checked it on holdout data.

Can ARIMA handle seasonal patterns in my data?

Standard ARIMA cannot handle seasonality. You need SARIMA (Seasonal ARIMA), which adds seasonal parameters (P, D, Q, s) to capture patterns that repeat at fixed intervals. For weekly patterns, s=52; for monthly, s=12. SARIMA needs several full seasonal cycles. If you have strong seasonality and limited data, consider seasonal decomposition first or try a method built for seasonality, such as Prophet.

How much historical data do I need for reliable ARIMA forecasts?

Enough observations to fit the terms you choose, and to test on held-out data. For seasonal ARIMA, you need several complete seasonal cycles. More data can help, but only if the underlying process is stable. If your business fundamentally changed, older data may hurt more than help. Always split your data: train on most of it, check on the rest, and never trust a forecast that has not been tested on out-of-sample data.

Related Articles