Time Series • Statistics Background for Forecasting
Time Series / P3.01 Calculate and Plot ACF

P3.01 Calculate and Plot ACF

Practical 3 Statistics Background for Forecasting

Compute and plot the sample autocorrelation function of a slowly changing series and of a white-noise series.

Practical / Solution

P3.01 Calculate and Plot ACF

Problem Statement

Compute and plot the sample autocorrelation function of a slowly changing series and of a white-noise series.

Learning Outcomes

  • Calculate sample ACF using statsmodels.
  • Compare a persistent series with noise.

Theory

Autocorrelation measures linear dependence between a series and its lagged values. For white noise, ACF should be near zero after lag 0. For a persistent series, ACF decays slowly.

Dataset / Data Source

Two constructed series of length 80: a random walk-like cumsum of noise, and independent noise. Teaching data.

Analysis / Program

import numpy as np import pandas as pd import matplotlib.pyplot as plt from statsmodels.graphics.tsaplots import plot_acf rng = np.random.default_rng(7) e = rng.normal(size=80) rw = pd.Series(np.cumsum(e)) wn = pd.Series(e) fig, axes = plt.subplots(1, 2, figsize=(9, 4)) plot_acf(rw, ax=axes[0], title="ACF of persistent series") plot_acf(wn, ax=axes[1], title="ACF of white noise") plt.tight_layout() plt.show()

Expected Output

Two ACF bar plots. The persistent series shows many significant early lags; white noise bars stay inside the confidence bands after lag 0.

Result / Interpretation

ACF is a dependence diagnostic. It does not by itself name the 'true' model, but it tells you whether independence is plausible.

Note

ACF helps identify dependence between current and past observations.