Book contents

STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 21

Introduction to Time Series Analysis

Time series are ordered sequences of observations collected over time, such as daily stock prices, monthly rainfall or annual GDP. Time series analysis focuses on modelling temporal dependence to understand underlying processes and make forecasts. This chapter introduces basic concepts, stationary processes, ARIMA models and seasonal decomposition.

Time Series Concepts

A time series {Xt}\{X_t\} is a sequence of random variables indexed by time tt. Key objectives include forecasting future values and understanding the structure of the series. Important concepts:

Autoregressive and Moving Average Models

Autoregressive (AR) Model: an AR(pp) process satisfies Xt=ϕ1Xt−1+⋯+ϕpXt−p+εt,X_t = \phi_1 X_{t-1} + \cdots + \phi_p X_{t-p} + \varepsilon_t, where εt\varepsilon_t are white noise errors. The AR(1) model is the simplest, with one lag.

Moving Average (MA) Model: an MA(qq) process is Xt=εt+θ1εt−1+⋯+θqεt−q.X_t = \varepsilon_t + \theta_1 \varepsilon_{t-1} + \cdots + \theta_q \varepsilon_{t-q}. AR and MA models can be combined into ARMA(p,qp,q) models.

ARIMA and Seasonal Models

Non–stationary series can be made stationary by differencing. An integrated ARMA (ARIMA) model of order (p,d,q)(p,d,q) applies dd differences and then fits an ARMA(p,qp,q) model. Seasonal patterns can be modelled using SARIMA models with seasonal differencing and seasonal autoregressive and moving average terms.

Example: Airline Passengers Dataset

The classic AirPassengers dataset contains monthly counts of international airline passengers from 1949 to 1960. It exhibits increasing trend and multiplicative seasonality. We can decompose and model it.

Worked example

Time series decomposition and forecasting.

library(forecast)
data(AirPassengers)
ap <- AirPassengers
decomp <- decompose(log(ap))
plot(decomp)

# Fit ARIMA model and forecast
fit <- auto.arima(log(ap))
forecasted <- forecast(fit, h=12)
plot(forecasted)
import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.arima.model import ARIMA
import matplotlib.pyplot as plt

# Load dataset
ap = sm.datasets.get_rdataset('AirPassengers').data
series = pd.Series(ap['value'].values, index=pd.date_range('1949-01', periods=len(ap), freq='M'))

decomp = seasonal_decompose(np.log(series), model='multiplicative')
decomp.plot()

model = ARIMA(np.log(series), order=(0,1,1), seasonal_order=(0,1,1,12)).fit()
forecast = model.get_forecast(steps=12)
forecast_ci = forecast.conf_int()

These commands decompose the series into trend, seasonal and irregular components and fit an ARIMA model to forecast future values.

Exercises

Practice

  1. For a given time series (e.g., daily temperature), plot the ACF and PACF. Identify an appropriate AR or MA order using the plots. Fit the model and forecast the next 10 values.

  2. Demonstrate differencing by simulating a random walk Xt=Xt−1+εtX_t = X_{t-1} + \varepsilon_t. Show that the differenced series is stationary.

  3. Apply seasonal decomposition to monthly electricity consumption data. Interpret the seasonal and trend components.

  4. Use cross–validation to compare forecasting accuracy of an ARIMA model and an exponential smoothing model on a time series of your choice.

References