← Back to list

ARIMA — Manual Calculations Explained

Ever felt like time-series forecasting is a bit of a “black box”? You feed data into a model, and out pops a prediction for the next month…

NeuralLearn · 2026-05-12 14:56 · 0 claps · 6.1 min read
#arima #time-series-forecasting #seasonality #arima-model #time-series-analysis
Open on Medium ↗
Wiki topics: 🔧 · Data Engineering

ARIMA — Manual Calculations Explained

Ever felt like time-series forecasting is a bit of a “black box”? You feed data into a model, and out pops a prediction for the next month. But what is actually happening under the hood?

In this post, we’re going to demystify the ARIMA model by walking through the manual calculations. We’ll use the classic **Air Passengers dataset** — which tracks monthly passengers from 1949 to 1960 — to see exactly how the math turns past data into future insights.

What is ARIMA anyway?

ARIMA is an acronym for AutoRegressive Integrated Moving Average. Each letter represents a “knob” you can turn to help the model fit your specific data.

1. p (AutoRegressive value)

The p parameter represents the AutoRegressive component.

  • It determines how many past values from the dataset are used to predict the future value.
  • For example, if p=1, the model uses the value from the immediate previous month to help calculate the next month.

2. d (Integrated value)

The d parameter is the Integrated component.

  • It defines the number of times the raw observations are differenced to reach stationarity.
  • Differencing involves subtracting the previous value from the current value.
  • If d=0, no differencing is applied, and the model works with the data as-is.

3. q (Moving Average value)

The q parameter represents the Moving Average component.

  • Instead of looking at past values (like p), q looks at how many past prediction errors are factored into the future value.
  • A prediction error (or residual) is the difference between what the model predicted and what actually happened.
  • If q=1, the model looks at the error from the last time step to “correct” its next prediction.

The Foundation: Why Stationarity?

In time series analysis, stationarity means that the statistical properties of a series — like its mean, variance, and autocorrelation — do not change over time.

Think of it like trying to predict the path of a ball. It is much easier to predict where the ball will land if it is rolling on a flat, consistent surface (stationary) than if it is on a moving escalator that is also vibrating (non-stationary).

Why is it needed?

  • Predictability: Most forecasting models assume that patterns found in past data will continue. If the mean is constantly shifting (due to a trend), those patterns become “moving targets.”
  • Mathematical Stability: Models like ARIMA require stabilized data so the coefficients can be estimated accurately.
  • Requirement for Differencing: If your data isn’t stationary, you must “difference” it — which is exactly what the d in ARIMA is for.

Scenario 1: ARIMA(1, 0, 1) — Forecasting Without Differencing

In our first scenario, we are looking at an ARIMA(1, 0, 1) model. This means we are using one past value (p=1), no differencing (d=0), and one past error (q=1) to make our prediction.

Where do the “Hyperparameter” Values Come From?

Before we crunch the numbers, we need our coefficients. These are generated when we run model.fit() in Python. The library uses Maximum Likelihood Estimation to find the best-fitting values.

From our SARIMAX Results table:

  • const (280.3009): The average level (mean) of the series.
  • ar.L1 (0.9373): The weight given to the previous month’s value.
  • ma.L1 (0.4264): The weight given to the previous month’s prediction error.

Why is the Constant Used?

When d=0, the model assumes the series fluctuates around a central value (the Constant). The model predicts the deviation from that mean. That is why the formula subtracts the constant from the past value before applying the coefficient, then adds it back at the end.

Step-by-Step: Predicting January 1961

To predict the first month outside our dataset, we use the last known data point (Dec 1960) and the last known error.

  • Dec 1960 Actual Value: 432
  • Dec 1960 Error (Residual): 73.538153

The Formula:

Jan_1961 = Constant + AR (Dec_1960 — Constant) + MA (Error_at_Dec_1960)

The Math:

  1. 280.3009 + 0.9373 (432–280.3009) + 0.4264 73.538153
  2. 280.3009 + 0.9373 * (151.6991) + 31.3566
  3. 280.3009 + 142.1876 + 31.3566 = 453.8451
  4. Rounded Result: 454

Step-by-Step: Predicting February 1961

Predicting the second step is slightly different. Since we are now in the “future,” we don’t have a real observation for January 1961 to compare against our prediction — so we don’t know what the error is.

The Rule: When calculating future steps where the actual error is unknown, the Moving Average (MA) part becomes zero.

The Formula:

Feb_1961 = Constant + AR * (Jan_1961 — Constant) + 0

The Math:

  1. 280.3009 + 0.9373 * (454–280.3009) + 0
  2. 280.3009 + 0.9373 * (173.6991)
  3. 280.3009 + 162.8082 = 443.1091
  4. Rounded Result: 443

Notice that February is lower than January because the model is slowly “pulling” the prediction back toward the long-term average (the constant).

Scenario 2: ARIMA(1, 1, 1) — Handling Trends with Differencing

Real-world data, like air passenger numbers, usually has a trend. To handle this, we turn the d knob to 1. When d=1, we are no longer predicting the raw number; we are predicting the change between months.

Step 1: Gathering the New Ingredients

The software recalculates the coefficients for this “differenced” data:

  • AR Coefficient (ar.L1): -0.4742
  • MA Coefficient (ma.L1): 0.8635
  • Dec 1960 Value: 432
  • Nov 1960 Value: 390
  • Dec 1960 Error: 73.713436

Step 2: Manually Calculating January 1961

The formula changes. Instead of a constant mean, we start with the last known value and add the predicted change.

The Formula:

Jan_1961 = Dec_1960 + AR (Dec_1960 — Nov_1960) + MA (Error_at_Dec_1960)

The Math:

  1. Last change: 432–390 = 42.
  2. Apply Coefficients: 432 + (-0.4742 42) + (0.8635 73.713436).
  3. Simplify: 432–19.9164 + 63.6515 = 475.7351.
  4. Rounded Result: 476.

Step 3: Manually Calculating February 1961

Again, the MA part becomes zero for the second step.

The Math:

  1. Predicted change: 476 (Jan, 1961) — 432 (Dec, 1960) = 44.
  2. Apply Coefficients: 476 + (-0.4742 * 44) + 0.
  3. Simplify: 476–20.8648 = 455.1352.
  4. Rounded Result: 455.

Scenario 3: SARIMA — Adding the Power of Seasonality

What if your data has a “rhythm”? Air travel peaks every July. To handle this, we use SARIMA (Seasonal ARIMA), which adds parameters (P, D, Q)s. in addition to (p,d,q). Here we use ARIMA(1, 1, 0) x (0, 1, 0, 12).

Seasonal Differencing (D): Instead of subtracting yesterday from today, you subtract the same point from the previous cycle (e.g., this January minus last January).

  • s (12): The cycle repeats every 12 months.
  • D (1): Seasonal Differencing. We compare this January to last January.

The Manual Calculation for January 1961

We start with last year’s value, add the recent trend, and adjust by our AR coefficient.

The Formula:

Jan_1961 = Jan_1960 + (Dec_1960 — Dec_1959) + AR * [(Dec_1960 — Dec_1959) — (Nov_1960 — Nov_1959)]

The Math:

  1. Seasonal Difference (Dec_1960 — Dec_1959): 432–405 = 27
  2. Seasonal Difference (Nov_1960 — Nov_1959): 390–362 = 28
  3. “Dec-Nov”: 27–28 = -1
  4. Apply AR Coefficient: -0.3076 * (-1) = 0.3076
  5. Jan_1960 = 417
  6. Assemble: 417 + 27 + 0.3076
  7. Total: 444.3076 (Rounded: 444)

The Final Verdict

At its heart, ARIMA is less about complex calculus and more about logical patterns. It breaks down the messy reality of time-series data into three simple questions:

  • AR (p): How much does yesterday matter?
  • I (d): Is there a trend we need to “flatten” to see the truth?
  • MA (q): How should we fix our past mistakes?

When you add Seasonality, you simply add a fourth question: “What did we do this time last year?”

By understanding these manual steps, the “black box” disappears. You can see that every prediction is just a calculated balance of historical baselines, recent momentum, and self-correcting error adjustments. The next time you see a forecast, you’ll know it’s not just a random guess — it’s the math of the past lighting the way for the future.

https://www.youtube.com/watch?v=wCG5sHn1lW0


메타데이터
post_id
fcf1df1fe4a0
slug
arima-manual-calculations-explained-fcf1df1fe4a0
url
https://medium.com/@neuralplay.ai/arima-manual-calculations-explained-fcf1df1fe4a0
canonical_url
https://medium.com/@neuralplay.ai/arima-manual-calculations-explained-fcf1df1fe4a0
author_url
https://medium.com/@neuralplay.ai
status
ok
fetched_at
2026-06-22 12:55:45