ARIMA – Handling Trend in Time Series
Until now, all our models had one big assumption:
The data must be stationary.
But real-world data almost never behaves that way. Sales grow, users increase, prices rise, demand changes.
This is where ARIMA becomes essential.
Why ARMA Is Not Enough
In the previous lesson, ARMA worked well only when:
- No trend
- No long-term growth or decline
But consider:
- Monthly revenue increasing year after year
- Population growth
- Energy consumption rising over decades
These series are non-stationary. ARMA will fail completely.
The Missing Piece: Differencing
ARIMA introduces one powerful idea:
Instead of modeling the data, model the change in data.
That change is called differencing.
Example:
- Today sales = 120
- Yesterday sales = 115
- Difference = +5
Differences often remove trends and make data stationary.
ARIMA(p, d, q) Explained Clearly
ARIMA has three parts:
- p → AR (past values)
- d → differencing (trend removal)
- q → MA (past errors)
Example:
ARIMA(1,1,1)
- 1 past value
- 1 difference
- 1 past error
Real-World Analogy
Think about driving uphill:
- Height = raw data
- Slope = difference
Instead of predicting your absolute height, you predict how steep the road is.
That makes prediction much easier.
Step 1: Non-Stationary Time Series
Let’s first create a series with a clear upward trend.
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)
time = np.arange(100)
trend = time * 0.4
noise = np.random.normal(0, 3, 100)
series = trend + noise
plt.plot(series)
plt.title("Non-Stationary Time Series")
plt.show()
This is what that data actually looks like:
Observation:
- Clear upward movement
- Mean changes over time
- Not stationary
Step 2: Apply Differencing
Now we subtract each value from the previous one.
diff_series = np.diff(series)
plt.plot(diff_series)
plt.title("Differenced Series")
plt.show()
Here is the differenced data:
What changed?
- Trend is removed
- Mean stays around zero
- Looks stationary
Why Differencing Works
Trend is slow movement.
Differencing removes slow movement and keeps short-term behavior.
AR and MA models work perfectly on this transformed data.
Putting It All Together: ARIMA Conceptually
ARIMA works like this:
- Difference the data (d times)
- Apply ARMA on the differenced series
- Convert predictions back to original scale
This is why ARIMA handles trends but ARMA cannot.
Visual Comparison: Before vs After Differencing
Interpretation:
- Raw series → growing, unstable
- Differenced series → stable, predictable
When Should You Use ARIMA?
- Data has trend
- No strong seasonality
- Short-term forecasting
Examples:
- Sales forecasting
- Demand prediction
- Traffic growth modeling
Practice Questions
Q1. What does “d” represent in ARIMA?
Q2. Why not apply ARMA directly to trending data?
Big Picture
AR remembers the past. MA corrects mistakes. Differencing removes trend.
ARIMA combines all three.
But what if seasonality also exists?
That leads directly to the next model.