Lecture notes. Written from the material of Berkeley Stat 153, licensed CC BY 4.0. These are notes, not a transcript: the material has been reorganised and rewritten. This adaptation carries the same licence, and the original is linked above.
104. The Posterior t-Distribution in Regression¶
What this covers¶
In Bayesian multiple linear regression with a flat prior, what is the exact posterior distribution of the coefficients \(\beta_0,\dots,\beta_m\), and why does it turn out to be a multivariate \(t\)-distribution rather than a normal one? This chapter derives that result from scratch, works out the properties of the multivariate \(t\)-density it produces, and uses it to build credible intervals for individual coefficients. It then turns to the natural next question — models where a parameter enters nonlinearly — and works two examples of the same idea: a change-of-slope ("broken-stick") regression and a sinusoidal model with unknown frequency. It assumes the ordinary least-squares matrix formulation (\(X\), \(y\), \(\hat\beta = (X^TX)^{-1}X^Ty\)) and the flat-prior Bayesian setup for linear regression from the preceding lecture.
Setting up the Bayesian model¶
In multiple linear regression there is one response \(y\) and \(m\) covariates \(x_1,\dots,x_m\), observed on \(n\) subjects: \((y_i, x_{i1},\dots,x_{im})\) for \(i=1,\dots,n\). The model is
For a Bayesian treatment we put a flat (improper) prior on the coefficients and on \(\log\sigma\):
for a very large \(C\). Combining this with the normal likelihood gives the joint posterior density
where \(S(\beta) := \sum_{i=1}^n (y_i - \beta_0 - \beta_1 x_{i1} - \dots - \beta_m x_{im})^2\) is the sum of squares. (The extra \(\sigma^{-1}\) beyond the usual \(\sigma^{-n}\) from the likelihood comes from the flat prior being on \(\log\sigma\) rather than \(\sigma\).)
Marginalizing out \(\sigma\)¶
The posterior over the coefficients alone is obtained by integrating out \(\sigma\):
dropping the indicator as \(C\to\infty\) (as in the linear-regression posterior derived earlier in the course, the bound \(C\) has essentially no effect). Substituting \(\sigma = s\sqrt{S(\beta)}\) turns the integral into
and the remaining integral over \(s\) is a constant that does not depend on \(\beta\). Hence
where \(\hat\beta\) is the least-squares estimator (multiplying by the constant \(S(\hat\beta)^{n/2}\) does not change the proportionality). It turns out that \((*)\) is exactly a multivariate \(t\)-density. The rest of this chapter explains why, and what that buys us.
Two facts about the sum of squares¶
Write the model in matrix form, \(y = X\beta+\epsilon\), with
so that \(S(\beta) = \|y-X\beta\|^2\). Two facts about \(S\) do all the work below.
Fact 1 (normal equations). The least-squares estimator is \(\hat\beta = (X^TX)^{-1}X^Ty\). To see this, expand \(S(\beta) = y^Ty - \beta^TX^Ty - y^TX\beta + \beta^TX^TX\beta\) and differentiate: \(\nabla S(\beta) = 2X^Ty - 2X^TX\beta\). Setting this to zero at \(\beta=\hat\beta\) gives \(X^TX\hat\beta = X^Ty\), i.e. \(\hat\beta=(X^TX)^{-1}X^Ty\).
Fact 2 (Pythagorean identity). For every \(\beta\),
Proof. Write \(y - X\beta = (y-X\hat\beta) + (X\hat\beta - X\beta)\) and expand the squared norm:
The cross term vanishes: \(\langle y-X\hat\beta, X\hat\beta-X\beta\rangle = (\hat\beta-\beta)^TX^T(y-X\hat\beta) = (\hat\beta-\beta)^T(X^Ty - X^TX\hat\beta) = 0\) by Fact 1. \(\square\)
Fact 2 says \(S(\beta)\) is a paraboloid centred at \(\hat\beta\) with curvature matrix \(X^TX\) — exactly the shape that will match a \(t\)-density.
Identifying the posterior as a multivariate \(t\)¶
The multivariate \(t\)-density \(t_p(\mu,\Sigma,\nu)\), for a \(p\times 1\) location \(\mu\), a \(p\times p\) scale matrix \(\Sigma\), and degrees of freedom \(\nu>0\), is
Now use Fact 2 to rewrite \((*)\):
Matching this to (3) with \(x=\beta\), \(p=m+1\), \(\mu=\hat\beta\), \(\nu+p=n\), and \(\Sigma^{-1}/\nu = X^TX/S(\hat\beta)\) gives \(\nu=n-m-1\) and \(\Sigma = \dfrac{S(\hat\beta)}{n-m-1}(X^TX)^{-1}\). So the posterior of the whole coefficient vector is exactly a multivariate \(t\):
This is the central result: the posterior is centred at the least-squares estimate, its spread is governed by the same \((X^TX)^{-1}\) that appears in the classical sampling covariance of \(\hat\beta\), and the degrees of freedom \(n-m-1\) is the usual residual degrees of freedom.
Properties of the multivariate \(t\)-density¶
Connection to the normal. The quadratic form \((x-\mu)^T\Sigma^{-1}(x-\mu)\) in (3) is the same one that appears in the multivariate normal density \(N_p(\mu,\Sigma)\). The precise link: if \(X\sim N_p(\mu,\Sigma)\) and \(V\sim\chi^2_\nu\) are independent, then
So \(t_p(\mu,\Sigma,\nu)\) is what you get by taking a normal vector and inflating its deviation from the mean by a random factor \(1/\sqrt{V/\nu}\) that is at least \(1\) on average — the extra randomness in that inflation factor is exactly what gives the \(t\)-distribution its heavier tails than the normal. A proof of (4) is given below.
Components and linear combinations are also \(t\). If \(T\sim t_p(\mu,\Sigma,\nu)\) with components \(T_1,\dots,T_p\), then every linear combination \(a_0+a^TT\) is univariate \(t\). Using (4),
and since \(a_0+a^TX \sim N(a_0+a^T\mu,\, a^T\Sigma a)\), applying (4) again (now in one dimension) gives
Taking \(a\) to be a coordinate vector, each component satisfies \(T_j\sim t_1(\mu_j,\Sigma(j,j),\nu)\), where \(\Sigma(j,j)\) is the \(j\)th diagonal entry of \(\Sigma\). This is what makes the individual \(\beta_j\) posteriors tractable even though the joint posterior (1) is a \((m+1)\)-dimensional object.
Large \(\nu\): \(t\) looks normal. When \(\nu\) is large, \((x-\mu)^T\Sigma^{-1}(x-\mu)/\nu\) is small, so using \(1+z\approx e^z\) for small \(z\),
because \((\nu+p)/\nu\approx 1\). So \(t_p(\mu,\Sigma,\nu)\approx N_p(\mu,\Sigma)\) for large \(\nu\). In the regression posterior (1), \(\nu=n-m-1\), so whenever there is a reasonable amount of data relative to the number of covariates, the exact \(t\)-posterior and the normal approximation
are close, and the extra machinery of this chapter matters most precisely when \(n-m-1\) is small.
Proof of the mixture representation (4)¶
Condition on \(V=x\): since \(T\mid V=x \sim N(\mu, \frac{\nu}{x}\Sigma)\),
using \(\det(\frac\nu x\Sigma) = (\nu/x)^p\det\Sigma\). Averaging over the \(\chi^2_\nu\) density of \(V\), \(f_V(x)\propto x^{\nu/2-1}e^{-x/2}\),
Substituting \(t = x\left[1+\frac1\nu(y-\mu)^T\Sigma^{-1}(y-\mu)\right]\) pulls the bracketed factor out of a now-standard Gamma integral:
which is exactly (3). \(\square\)
Back to regression: intervals for individual coefficients¶
Write \(\hat\sigma^2 := S(\hat\beta)/(n-m-1)\), so that \(\hat\sigma\) is the usual (frequentist) unbiased estimator of \(\sigma\) — it can also be justified directly as a Bayesian point estimator, which is the content of a homework exercise. It is commonly called the residual standard error. With this notation, (1) becomes
Because components of a multivariate \(t\) are univariate \(t\), each coefficient's posterior is
where \((X^TX)^{j+1,j+1}\) is the \((j+1)\)th diagonal entry of \((X^TX)^{-1}\) (the shift by one is because \(\beta_j\) is the \((j+1)\)th entry of \(\beta\), the \(0\)th entry being \(\beta_0\)). Equivalently,
and the quantity \(\hat\sigma\sqrt{(X^TX)^{j+1,j+1}}\) is the standard error of \(\beta_j\). Letting \(t_{n-m-1,\alpha/2}\) denote the point beyond which the \(t_{n-m-1}\) distribution puts probability \(\alpha/2\), this pivot gives
The resulting interval is the \(100(1-\alpha)\%\) Bayesian credible interval for \(\beta_j\), and it coincides exactly with the frequentist \(100(1-\alpha)\%\) confidence interval — the two philosophies give the same numbers here, even though they mean different things by the probability statement. When \(n-m-1\) is large, this reduces to the familiar normal-based interval, since (6) and its components are then close to \(N_{m+1}(\hat\beta,\hat\sigma^2(X^TX)^{-1})\) and \(N(\hat\beta_j,\hat\sigma^2(X^TX)^{j+1,j+1})\) respectively.
Extending to nonlinear regression¶
Everything above assumed the covariates enter the model linearly, so that \(y = X\beta+\epsilon\) for a design matrix \(X\) built purely from the data. The next class of models has a parameter that enters nonlinearly — through the argument of a function rather than as a coefficient. If that nonlinear parameter were known, the model would collapse back to ordinary linear regression; the difficulty is that it is not known, and it cannot be profiled out algebraically the way \(\beta\) can. The recipe used for both examples below is the same: fix the nonlinear parameter, minimize the sum of squares over the linear coefficients (that's a linear-regression problem, solved as above), and then search over the nonlinear parameter to minimize the resulting residual sum of squares.
Example: the sinusoidal model¶
A sinusoid is \(s(t) = R\cos(2\pi ft+\phi)\), with amplitude \(R\), frequency \(f\), phase \(\phi\), and period \(1/f\). Using \(\cos(\alpha+\beta)=\cos\alpha\cos\beta-\sin\alpha\sin\beta\), it can be rewritten as
a form in which \(A,B\) appear linearly — the reason this representation is preferred when \(s(t)\) is embedded in a regression model. When time is sampled at integers \(t=1,\dots,n\), the frequency can always be taken to lie in \([0,1/2]\) without loss of generality:
Fact. For every \(f,\phi\in(-\infty,\infty)\) there exist \(f_0\in[0,1/2]\) and \(\phi_0\) with \(R\cos(2\pi ft+\phi) = R\cos(2\pi f_0t+\phi_0)\) for every integer \(t\).
Proof. If \(f<0\), use \(\cos(2\pi ft+\phi)=\cos(2\pi(-f)t-\phi)\) and \(-f\ge 0\). If \(f\ge 1\), write \(f=[f]+(f-[f])\); since \(\cos\) has period \(2\pi\) and \([f]\) is an integer, \(\cos(2\pi ft+\phi) = \cos(2\pi(f-[f])t+\phi)\) with \(0\le f-[f]<1\). If \(f\in[1/2,1)\), use \(\cos(2\pi ft+\phi)=\cos(2\pi t - 2\pi(1-f)t+\phi)=\cos(2\pi(1-f)t-\phi)\) (valid since \(t\) is an integer), and \(0<1-f\le 1/2\). Chaining these reduces any \(f\) to some \(f_0\in[0,1/2]\). \(\square\)
At the boundary \(f=0\), \(s(t)=R\cos\phi\) is constant; at \(f=1/2\), \(s(t)=R(-1)^t\cos\phi\) oscillates maximally between \(R\cos\phi\) and \(-R\cos\phi\).
The sinusoidal regression model for a series \(y_1,\dots,y_n\) is
with unknowns \(\beta_0,\beta_1,\beta_2,\sigma,f\), and \(f\in[0,1/2]\) unknown (as for the sunspots data the course fits it to). If \(f\) were known this is ordinary linear regression with design matrix
MLE. For fixed \(f\), \(S(\beta,f)=\|y-X_f\beta\|^2\) is minimized at \(\hat\beta(f)=(X_f^TX_f)^{-1}X_f^Ty\), giving \(\text{RSS}(f) := S(\hat\beta(f),f) = \min_\beta S(\beta,f)\). Since \(\min_{\beta,f}S(\beta,f)=\min_f\text{RSS}(f)\), the MLE is found by: (1) grid the candidate frequencies \(f\in[0,1/2]\); (2) for each grid value, regress \(y\) on \(X_f\) and record \(\text{RSS}(f)\); (3) take \(\hat f\) to minimize \(\text{RSS}(f)\) over the grid; (4) take \(\hat\beta,\hat\sigma\) from the ordinary regression of \(y\) on \(X_{\hat f}\).
Bayesian posterior for \(f\). Uncertainty quantification for \(\hat f\) is awkward classically, so the course turns to the Bayesian route instead, with independent priors \(\beta_0,\beta_1,\beta_2,\log\sigma\sim\text{unif}(-C,C)\) and \(f\sim\text{unif}[0,1/2]\). Dropping the \(C\)-indicators as before, the joint posterior is
To get the marginal posterior of \(f\) — the parameter of real interest — integrate out \(\beta\) and \(\sigma\). First, using the Pythagorean identity applied to \(S(\beta,f)\) (in \(\beta\), for fixed \(f\)), the inner integral over \(\beta\) is the normalizing constant of a \(p\)-dimensional normal density (\(p=3\) here):
Substituting this in and integrating over \(\sigma\) exactly as in the marginalization step earlier in this chapter — except that the extra factor \(\sigma^p\) shifts the power of \(\sigma\) from \(-n-1\) to \(-n+p-1\), which is the same computation with \(n\) replaced by \(n-p\) — gives
The dominant term is \(\text{RSS}(f)^{-(n-p)/2}\): it is largest at the MLE \(\hat f\), and the exponent \(n-p\) controls how tightly the posterior concentrates there — tighter as \(n\) grows. This posterior is evaluated numerically over a grid of \(f\in(0,1/2)\); the endpoints \(f=0,1/2\) must be excluded because there \(X_f\) loses full column rank and \(|X_f^TX_f|^{-1/2}\) blows up.
Example: change-of-slope ("broken-stick") regression¶
A second nonlinear model changes the slope of a straight line at an unknown time \(c\):
where \(\text{ReLU}(t-c)=(t-c)_+=(t-c)I\{t>c\}=\max(t-c,0)\) is the positive-part (ramp) function. For \(t\le c\) the slope of the mean function is \(\beta_1\); for \(t>c\) it becomes \(\beta_1+\beta_2\) — hence "change of slope", or "broken-stick regression", for the shape of the resulting piecewise-linear curve.
The unknown parameters are \(c,\beta_0,\beta_1,\beta_2,\sigma\); it is \(c\) that makes the model nonlinear. If \(c\) were known, this is again ordinary linear regression, \(y=X_c\beta+\epsilon\), with
Least squares again minimizes \(S(\beta,c) = \|y-X_c\beta\|^2\) over all four unknowns \(\beta_0,\beta_1,\beta_2,c\). Exactly as in the sinusoidal case, fixing \(c\) turns this into an ordinary linear-regression problem, minimized (by Fact 1 above) at
The source material breaks off at this formula. The natural continuation — following exactly the same recipe carried through in full for the frequency \(f\) above — would be to record \(\text{RSS}(c) = S(\hat\beta_c,c)\), grid the candidate values of \(c\), and take \(\hat c\) to be the grid value minimizing \(\text{RSS}(c)\); this is not spelled out in the lecture material supplied here.
Sources¶
- Derivation of the Bayesian posterior for \(\beta\) via marginalizing out \(\sigma\) (the flat-prior model, the \(\sigma^{-n-1}\) joint posterior, and the integral leading to \((*)\)): STAT 153/248, UC Berkeley, Fall 2026, Lecture Five, §1 ("Bayesian Inference for Linear Regression" through §1.2), Aditya Guntuboyina, 10 September 2026.
- Matrix notation, Fact 1 (normal equations) and Fact 2 (Pythagorean identity), and the matching of the posterior to the multivariate \(t\)-density giving (1): same source, §1.2, and cross-checked against Fall 2025, Lecture Five, part 1 ("1 Posterior \(t\)-density in Multiple Linear Regression"), 11 September 2025, which states result (1) without re-deriving it ("In the last lecture, we saw the following formula...") — the Fall 2026 notes supply the derivation the Fall 2025 notes assume.
- Definition and properties of the multivariate \(t\)-density \(t_p(\mu,\Sigma,\nu)\) (mixture representation, components/linear combinations also \(t\), large-\(\nu\) normal approximation): Fall 2025, Lecture Five, part 2 ("2 \(t\)-density"), matching Fall 2026 §1.1 essentially verbatim. Both cite Wikipedia's article on the multivariate \(t\)-distribution as their source for the density formula.
- Proof of the mixture representation (4): Fall 2025, Lecture Five, part 4 ("4 Proof of (4)").
- Credible intervals for individual \(\beta_j\), the residual standard error \(\hat\sigma\), and the equivalence with the frequentist confidence interval: Fall 2025, Lecture Five, part 3 ("3 Back to Regression"), matching Fall 2026 §1.3. The claim that \(\hat\sigma\) is also a Bayesian estimator is attributed to a homework exercise — Fall 2025 cites "Question 5(e) of Homework One", Fall 2026 cites "Question 4(e) of Homework One"; the homework itself is not part of the supplied material.
- The general nonlinear-regression framing and the change-of-slope/broken-stick model: Fall 2025, Lecture Five, part 5 ("5 Nonlinear Regression"). This file is truncated mid-derivation in the source conversion, immediately after the formula for \(\hat\beta_c\); nothing past that point was taught in the supplied material, and the closing paragraph of that section says so explicitly.
- The sinusoidal model, the restriction of frequency to \([0,1/2]\) and its proof, the MLE grid-search algorithm, and the Bayesian marginal posterior for \(f\): STAT 153/248, Spring 2025, Lecture Five, parts 2–3 ("2 The Sinusoid", "3 The sinusoidal model"), Aditya Guntuboyina, 4 February 2025.
- All of the above are model-reconstructed conversions (route: llm, fidelity: reconstructed) of PDF slide/notes decks with no text layer; per their own headers, every displayed equation is unverified against the original PDF. Treat the numbered equations here as a best-effort transcription of that reconstruction, not as independently checked mathematics.
← 103. Smoothing the Periodogram (part 3) · Contents · 105. Frequentist and Bayesian Linear Regression →