Skip to content

Bayesian linear regression

Update a Gaussian coefficient prior and distinguish posterior coefficient uncertainty, latent-response uncertainty and new-observation predictive uncertainty.

Bayesian linear regression puts a prior distribution on the coefficients of a linear regression and updates it with observed data to obtain a posterior distribution. A quant estimating a factor exposure can then carry uncertainty about that exposure into a conditional prediction, instead of treating one fitted slope as certain.
The crucial distinction is between uncertainty about a coefficient, uncertainty about the mean response, and uncertainty about a new observation. Those three distributions can have very different variances.

Specify the model before updating it

For a design matrix XX with one observation per row, consider

y=Xβ+ε,ε∼N(0,σ2I),β∼N(m0,V0).\mathbf y=X\boldsymbol\beta+\boldsymbol\varepsilon, \qquad \boldsymbol\varepsilon\sim\mathcal N(\mathbf 0,\sigma^2 I), \qquad \boldsymbol\beta\sim\mathcal N(\mathbf m_0,V_0).
Here inputs are conditioned on, noise is independent across observations and independent of the coefficients, σ2>0\sigma^2>0 is known, and V0V_0 is positive definite. An intercept, if wanted, needs its own column of ones and a specified prior. “Linear” means linear in the coefficients; predetermined nonlinear transformations of inputs can also appear as columns of XX.
The prior expresses assumptions before these observations. Multiplying its density by the likelihood and normalising gives a Gaussian posterior:
Vn=(V0−1+X⊤Xσ2)−1,mn=Vn(V0−1m0+X⊤yσ2),β∣D∼N(mn,Vn),D=(X,y).\begin{aligned} V_n&=\left(V_0^{-1}+\frac{X^\top X}{\sigma^2}\right)^{-1},\\ \mathbf m_n&=V_n\left(V_0^{-1}\mathbf m_0+\frac{X^\top\mathbf y}{\sigma^2}\right),\\ \boldsymbol\beta\mid D&\sim\mathcal N(\mathbf m_n,V_n), \qquad D=(X,\mathbf y). \end{aligned}
Prior and data precisions, meaning inverse covariances here, add. These are the Gaussian update formulas developed in Rasmussen and Williams, §2.1.1, written with observations in rows rather than their column convention.

Two observations, three uncertainty statements

Take an original, synthetic scalar example in arbitrary units:

yi=xiβ+εi,β∼N(0,1),εi∼iidN(0,1).y_i=x_i\beta+\varepsilon_i, \qquad \beta\sim\mathcal N(0,1), \qquad \varepsilon_i\stackrel{\mathrm{iid}}{\sim}\mathcal N(0,1).
There is no intercept. Observe (x1,y1)=(1,1)(x_1,y_1)=(1,1) and (x2,y2)=(2,2)(x_2,y_2)=(2,2). Although the two points lie exactly on y=xy=x, the model stipulates noise variance one; two neat points do not make it zero.

The scalar update is

vn=11+12+22=16,mn=vn(1⋅1+2⋅2)=56.v_n=\frac{1}{1+1^2+2^2}=\frac16, \qquad m_n=v_n(1\cdot1+2\cdot2)=\frac56.

Thus β∣D∼N(5/6,1/6)\beta\mid D\sim\mathcal N(5/6,1/6). To see the update directly, the negative log posterior, up to constants and a factor of one half, contains

β2+(1−β)2+(2−2β)2=6(β−56)2+56.\beta^2+(1-\beta)^2+(2-2\beta)^2 =6\left(\beta-\frac56\right)^2+\frac56.

The no-intercept least-squares slope is 11. The posterior mean 5/65/6 is pulled toward the prior mean zero: a concrete instance of shrinkage.

Now supply a new input x∗=3x_*=3. Define the latent response f∗=3βf_*=3\beta and a fresh observation y∗=3β+ε∗y_*=3\beta+\varepsilon_*, where the new noise is independent and has variance one.

Quantity, conditional on the observed dataMeanVariance
Coefficient β\beta5/65/61/61/6
Latent mean response f∗=3βf_*=3\beta2.52.59/6=1.59/6=1.5
New observation y∗y_* at x∗=3x_*=32.52.51+1.5=2.51+1.5=2.5

Coefficient variance is in squared coefficient units; the other two variances are in squared response units. Equal means do not make the latent response and the new observation interchangeable.

Synthetic no-intercept example. The coefficient prior has mean zero and variance one; its posterior has mean five sixths and variance one sixth. At input three, the latent response and new observation both have mean 2.5, with variances 1.5 and 2.5 respectively.
Synthetic no-intercept example. The coefficient prior has mean zero and variance one; its posterior has mean five sixths and variance one sixth. At input three, the latent response and new observation both have mean 2.5, with variances 1.5 and 2.5 respectively.
Original synthetic example. The upper panel compares coefficient densities; the lower panel compares response densities at a supplied input of three. The wider dashed response curve includes fresh observation noise.

Prediction averages over the coefficients

For a supplied vector x∗\mathbf x_*, integrating over the coefficient posterior gives

f∗∣D,x∗∼N(x∗⊤mn,  x∗⊤Vnx∗),y∗∣D,x∗∼N(x∗⊤mn,  σ2+x∗⊤Vnx∗).\begin{aligned} f_*\mid D,\mathbf x_*&\sim\mathcal N(\mathbf x_*^\top\mathbf m_n,\;\mathbf x_*^\top V_n\mathbf x_*),\\ y_*\mid D,\mathbf x_*&\sim\mathcal N(\mathbf x_*^\top\mathbf m_n,\;\sigma^2+\mathbf x_*^\top V_n\mathbf x_*). \end{aligned}
The second variance adds the noise remaining even if the coefficients were known. Plugging the posterior mean into the observation model would retain only σ2\sigma^2 and discard coefficient uncertainty. Hughes's Tufts notes, Parts 2–4, contrast these prediction strategies.

In the example, x∗=3x_*=3 lies outside the observed input range. The larger latent variance reflects slope uncertainty under the stipulated straight-line model. It does not measure how wrong that model might be outside its training range. At x∗=0x_*=0, latent variance is exactly zero because the no-intercept specification forces the mean response to zero; a new observation still has variance one.

What the posterior leaves conditional

A zero-centred Gaussian prior produces a quadratic coefficient penalty. In the isotropic case V0=τ2IV_0=\tau^2I, the posterior mode minimises squared residuals plus (σ2/τ2)∥β∥2(\sigma^2/\tau^2)\lVert\boldsymbol\beta\rVert^2: the ridge regression connection. Matching a point estimate does not supply the whole posterior. Prior scale also depends on input units; rescaling a predictor while retaining the same numerical coefficient prior changes the model.

Known noise variance is a deliberate simplification. If variance is unknown, it needs a prior and joint updating. Under an appropriate conjugate normal–inverse-gamma specification, integrating it out produces Student-t coefficient and predictive distributions; this is not achieved by silently replacing σ2\sigma^2 with a residual estimate. Taboga's treatment separates the known- and unknown-variance models. Other priors need not give the same distributional form.

For financial data, serially dependent or changing-variance errors, unstable exposures and omitted predictors can invalidate the stated likelihood. A narrow posterior is conditional on that likelihood and prior. It is not evidence that those choices are correct.

Finally, an exposure regression using market and asset returns from the same period is an in-sample relationship. A forecast requires inputs available at its decision time, a specified horizon and evaluation on later unseen outcomes. If a future predictor is itself unknown, these conditional formulas do not integrate its uncertainty. Bayesian updating does not remove look-ahead bias.
For the conjugate-update foundation, read Bayesian Reasoning. For the least-squares comparison and coefficient inference, read Linear Regression. Both full lessons require membership, with public previews.

Sources

Last updated
  • bayesian regression
  • gaussian prior
  • posterior prediction
  • coefficient uncertainty
  • shrinkage
← Back to the glossaryBack to top ↑