Time Series • Time Series Regression Model
Time Series / P5.06 Bayesian Forecasting Idea

P5.06 Bayesian Forecasting Idea

Practical 5 Time Series Regression Model

Forecast the next mean of a small series using a beginner Bayesian update: a prior guess for the mean, a likelihood from the data, and a posterior mean used as the forecast. Keep the mathematics light.

Practical / Solution

P5.06 Bayesian Forecasting Idea

Problem Statement

Forecast the next mean of a small series using a beginner Bayesian update: a prior guess for the mean, a likelihood from the data, and a posterior mean used as the forecast. Keep the mathematics light.

Learning Outcomes

  • State prior, likelihood and posterior in words.
  • Combine a prior mean with the sample mean.
  • Interpret the posterior mean as a shrinkage forecast.

Theory

Bayesian forecasting starts with a prior belief about an unknown quantity, updates that belief with the likelihood of the observed data, and uses the posterior for prediction. In the simplest normal-mean teaching case, the posterior mean is a weighted average of the prior mean and the sample mean. More data pulls the forecast toward the sample. A strong prior pulls it toward the guess. This practical does not develop MCMC or full Bayesian VARs.

Dataset / Data Source

Ten demand observations: 30, 32, 31, 29, 33, 30, 31, 28, 32, 30. Prior guess: mean 35 with modest confidence, as if last year ran hotter. Teaching numbers.

Analysis / Program

import numpy as np y = np.array([30, 32, 31, 29, 33, 30, 31, 28, 32, 30], dtype=float) # Prior: mean m0, strength n0 (like prior sample size) m0, n0 = 35.0, 4 # Likelihood: sample mean with n observations n = len(y) ybar = y.mean() # Posterior mean for a simple normal-mean teaching update n1 = n0 + n m1 = (n0 * m0 + n * ybar) / n1 print("Sample mean (likelihood summary):", round(ybar, 3)) print("Prior mean:", m0) print("Posterior mean (forecast of the level):", round(m1, 3)) print("Weight on data:", round(n / n1, 3), "weight on prior:", round(n0 / n1, 3))

Expected Output

Printed sample mean near 30.6, prior 35, and a posterior mean between them, closer to the data because n = 10 is larger than n0 = 4. The exact posterior equals (4×35 + 10×ȳ) / 14.

Result / Interpretation

The forecast of the level shrinks the sample mean toward 35. That is the Bayesian idea in one number: combine prior and data. A full Bayesian time-series model would also put priors on persistence and seasonality; this lab only introduces the update.

Note

A Bayesian forecast combines a prior with the likelihood. The posterior mean shrinks the sample toward the prior.