advanced 30 minutes

Introduction to Time Series Analysis

Learn the fundamentals of time series data. Understand trends, seasonality, stationarity, and basic forecasting techniques.

On This Page
Advertisement

What is Time Series Data?

Time series data is a sequence of observations collected over time, typically at regular intervals.

Time Series Examples
  • Stock prices (daily closing prices)
  • Temperature (hourly readings)
  • Sales figures (monthly revenue)
  • Website traffic (daily visitors)
  • Heart rate (continuous monitoring)

Key Characteristics

FeatureDescription
Temporal orderingObservations have a natural time sequence
DependenceValues often depend on previous values
Regular intervalsUsually measured at fixed time periods
Single variableFocus on how one variable changes over time

Components of Time Series

Most time series can be decomposed into four components:

Time Series Decomposition

Additive model: Yt=Tt+St+Ct+ItY_t = T_t + S_t + C_t + I_t

Multiplicative model: Yt=Tt×St×Ct×ItY_t = T_t \times S_t \times C_t \times I_t

1. Trend (T)

The long-term movement in the data—overall increase or decrease over time.

Trend Examples
  • 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).

Seasonal Patterns
  • 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
Stationary vs Non-Stationary

Non-stationary: Stock prices (trending up/down) Stationary: Stock returns (percentage changes)

Converting prices to returns often creates stationarity.

Making Data Stationary

TechniqueWhen to Use
DifferencingRemove trend
Log transformationStabilize variance
Seasonal differencingRemove seasonality
DetrendingRemove linear trend
Differencing

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.

Autocorrelation Function (ACF)

ρₖ = Cov(Yₜ, Yₜ₋ₖ) / Var(Yₜ)

Where k is the lag (number of periods back)

Interpreting ACF Plots

PatternInterpretation
Slow decayNon-stationary (needs differencing)
Cut-off after lag kMA(k) process
Gradual decayAR process
Seasonal spikesSeasonal component present
Reading ACF

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 PatternPACF PatternSuggested Model
Tails offCuts off at pAR(p)
Cuts off at qTails offMA(q)
Tails offTails offARMA(p,q)

Basic Forecasting Methods

1. Simple Moving Average

Simple Moving Average

Y^t+1=1ki=0k1Yti\hat{Y}_{t+1} = \frac{1}{k}\sum_{i=0}^{k-1} Y_{t-i}

Average of the last k observations

3-Period Moving Average

Sales data: 100, 120, 110, 130, 115

Forecast for next period: = (110 + 130 + 115) / 3 = 118.3

2. Exponential Smoothing

Simple Exponential Smoothing

Y^t+1=αYt+(1α)Y^t\hat{Y}_{t+1} = \alpha Y_t + (1-\alpha)\hat{Y}_t

Where α is the smoothing parameter (0 to 1)

α ValueBehavior
Close to 1React quickly to changes
Close to 0Smooth, slow to react

3. Linear Trend Model

Linear Trend

Y^t=a+bt\hat{Y}_t = a + bt

Where t is the time index

4. Seasonal Naive

Use the value from the same season last cycle:

Y^t+1=Yt+1s\hat{Y}_{t+1} = Y_{t+1-s}

Where s is the seasonal period (e.g., 12 for monthly data with yearly seasons).


ARIMA Models

ARIMA(p, d, q) Components

ParameterMeaning
pAR order (autoregressive terms)
dDifferencing order (integration)
qMA order (moving average terms)
ARIMA Model

For ARIMA(1,1,1):

Y’ₜ = c + φY’ₜ₋₁ + θεₜ₋₁ + εₜ

Where Y’ is the differenced series

Common ARIMA Models

ModelNameUse Case
ARIMA(0,1,0)Random walkStock prices
ARIMA(1,0,0)AR(1)Simple autocorrelation
ARIMA(0,0,1)MA(1)Shock effects
ARIMA(1,1,1)Common mixedGeneral time series

Evaluating Forecasts

Accuracy Metrics

Mean Absolute Error (MAE)

MAE = (1/n) × Σ|Yᵢ - Ŷᵢ|

Root Mean Squared Error (RMSE)

RMSE = √[(1/n) × Σ(Yᵢ - Ŷᵢ)²]

Mean Absolute Percentage Error (MAPE)

MAPE = (100/n) × Σ|(Yᵢ - Ŷᵢ)/Yᵢ|

MetricAdvantagesDisadvantages
MAEEasy to interpretScale-dependent
RMSEPenalizes large errorsScale-dependent
MAPEScale-independentUndefined when Y=0

Train-Test Split


Practical Example

Monthly Sales Forecasting

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:

Advertisement

Was this lesson helpful?

Help us improve by sharing your feedback or spreading the word.