Introduction to Time Series Analysis
Learn the fundamentals of time series data. Understand trends, seasonality, stationarity, and basic forecasting techniques.
On This Page
What is Time Series Data?
Time series data is a sequence of observations collected over time, typically at regular intervals.
- Stock prices (daily closing prices)
- Temperature (hourly readings)
- Sales figures (monthly revenue)
- Website traffic (daily visitors)
- Heart rate (continuous monitoring)
Key Characteristics
| Feature | Description |
|---|---|
| Temporal ordering | Observations have a natural time sequence |
| Dependence | Values often depend on previous values |
| Regular intervals | Usually measured at fixed time periods |
| Single variable | Focus on how one variable changes over time |
Components of Time Series
Most time series can be decomposed into four components:
Additive model:
Multiplicative model:
1. Trend (T)
The long-term movement in the data—overall increase or decrease over time.
- Upward trend: Population growth over decades
- Downward trend: Manufacturing costs with technological improvement
- No trend: Temperature fluctuations around a stable average
2. Seasonality (S)
Regular, predictable patterns that repeat at fixed intervals (daily, weekly, yearly).
- Ice cream sales peak in summer (yearly cycle)
- Restaurant traffic peaks at lunch/dinner (daily cycle)
- Retail sales spike in December (yearly cycle)
3. Cyclical (C)
Longer-term fluctuations that don’t have fixed periods (economic cycles, business cycles).
Unlike seasonality, cyclical patterns:
- Don’t have fixed period length
- Often related to economic conditions
- Can last years
4. Irregular/Random (I)
Unpredictable, random variation that can’t be attributed to other components.
Stationarity
Why Stationarity Matters
- Non-stationary data can lead to spurious correlations
- Statistical tests assume stationarity
- Forecasting models work better with stationary data
Testing for Stationarity
Visual inspection: Does the series look stable over time?
Statistical tests:
- Augmented Dickey-Fuller (ADF) test
- KPSS test
- Phillips-Perron test
Non-stationary: Stock prices (trending up/down) Stationary: Stock returns (percentage changes)
Converting prices to returns often creates stationarity.
Making Data Stationary
| Technique | When to Use |
|---|---|
| Differencing | Remove trend |
| Log transformation | Stabilize variance |
| Seasonal differencing | Remove seasonality |
| Detrending | Remove linear trend |
First difference: Y’ₜ = Yₜ - Yₜ₋₁
Second difference: Y”ₜ = Y’ₜ - Y’ₜ₋₁
Seasonal difference: Y’ₜ = Yₜ - Yₜ₋ₛ (s = seasonal period)
Autocorrelation
Autocorrelation measures how a series correlates with its past values.
ρₖ = Cov(Yₜ, Yₜ₋ₖ) / Var(Yₜ)
Where k is the lag (number of periods back)
Interpreting ACF Plots
| Pattern | Interpretation |
|---|---|
| Slow decay | Non-stationary (needs differencing) |
| Cut-off after lag k | MA(k) process |
| Gradual decay | AR process |
| Seasonal spikes | Seasonal component present |
If autocorrelation is high at lag 1 but drops quickly:
- Today’s value strongly relates to yesterday’s
- But not to values further back
- Suggests AR(1) model
Partial Autocorrelation (PACF)
PACF measures correlation with lag k after removing effects of intermediate lags.
| ACF Pattern | PACF Pattern | Suggested Model |
|---|---|---|
| Tails off | Cuts off at p | AR(p) |
| Cuts off at q | Tails off | MA(q) |
| Tails off | Tails off | ARMA(p,q) |
Basic Forecasting Methods
1. Simple Moving Average
Average of the last k observations
Sales data: 100, 120, 110, 130, 115
Forecast for next period: = (110 + 130 + 115) / 3 = 118.3
2. Exponential Smoothing
Where α is the smoothing parameter (0 to 1)
| α Value | Behavior |
|---|---|
| Close to 1 | React quickly to changes |
| Close to 0 | Smooth, slow to react |
3. Linear Trend Model
Where t is the time index
4. Seasonal Naive
Use the value from the same season last cycle:
Where s is the seasonal period (e.g., 12 for monthly data with yearly seasons).
ARIMA Models
ARIMA(p, d, q) Components
| Parameter | Meaning |
|---|---|
| p | AR order (autoregressive terms) |
| d | Differencing order (integration) |
| q | MA order (moving average terms) |
For ARIMA(1,1,1):
Y’ₜ = c + φY’ₜ₋₁ + θεₜ₋₁ + εₜ
Where Y’ is the differenced series
Common ARIMA Models
| Model | Name | Use Case |
|---|---|---|
| ARIMA(0,1,0) | Random walk | Stock prices |
| ARIMA(1,0,0) | AR(1) | Simple autocorrelation |
| ARIMA(0,0,1) | MA(1) | Shock effects |
| ARIMA(1,1,1) | Common mixed | General time series |
Evaluating Forecasts
Accuracy Metrics
MAE = (1/n) × Σ|Yᵢ - Ŷᵢ|
RMSE = √[(1/n) × Σ(Yᵢ - Ŷᵢ)²]
MAPE = (100/n) × Σ|(Yᵢ - Ŷᵢ)/Yᵢ|
| Metric | Advantages | Disadvantages |
|---|---|---|
| MAE | Easy to interpret | Scale-dependent |
| RMSE | Penalizes large errors | Scale-dependent |
| MAPE | Scale-independent | Undefined when Y=0 |
Train-Test Split
Practical Example
Data: 24 months of sales data
Step 1: Plot the data
- Notice upward trend
- See seasonal peaks in December
Step 2: Check stationarity
- ADF test shows non-stationary
- Apply first differencing
Step 3: Analyze ACF/PACF
- Significant spike at lag 12 (seasonality)
- Decay pattern suggests AR component
Step 4: Fit model
- ARIMA(1,1,0) with seasonal component
Step 5: Evaluate
- MAPE = 8.5% on test data
- Residuals appear random (good!)
Step 6: Forecast
- Generate predictions for next 6 months
Summary
In this lesson, you learned:
- Time series has four components: Trend, Seasonality, Cyclical, Irregular
- Stationarity is required for most methods (constant mean/variance)
- Autocorrelation (ACF) measures correlation with past values
- Differencing removes trend to achieve stationarity
- Moving averages and exponential smoothing are simple forecasting methods
- ARIMA(p,d,q) combines AR, differencing, and MA components
- Evaluate forecasts with MAE, RMSE, or MAPE
- Always use chronological train-test splits
Practice Problems
1. A time series has these values: 10, 12, 11, 13, 12, 14 Calculate the first differences.
2. Which component explains: a) Steady increase in temperature over decades? b) Higher ice cream sales every summer? c) Economic recession effects?
3. You have monthly data with a yearly seasonal pattern. What lag would you expect to show high autocorrelation?
4. A forecast has MAE = 5 and the average actual value is 100. Is this forecast accurate?
Click to see answers
1. First differences (Yₜ - Yₜ₋₁):
- 12 - 10 = 2
- 11 - 12 = -1
- 13 - 11 = 2
- 12 - 13 = -1
- 14 - 12 = 2
First differences: 2, -1, 2, -1, 2
2. a) Trend - long-term directional movement b) Seasonality - regular yearly pattern c) Cyclical - irregular longer-term fluctuations
3. Lag 12 (12 months = 1 year)
The autocorrelation at lag 12 would be high because January this year relates to January last year, etc.
4. MAE of 5 with average value of 100 is relatively small (5% relative error).
This is reasonably accurate, though “good” depends on the application. For many business forecasts, less than 10% error is acceptable.
Next Steps
Continue your statistics journey:
- Linear Regression - Foundation for time series regression
- Correlation - Understanding relationships
- Bayesian Statistics - Alternative inference framework
Was this lesson helpful?
Help us improve by sharing your feedback or spreading the word.