Prediction interval in a normal linear model (source code)

= Prediction interval in a normal linear model

For the full-rank <normal linear model> $Y=X\beta+\varepsilon$ and an independent future response $Y^*=x^{*T}\beta+\varepsilon^*$, put
$$
s^2=\frac{\operatorname{RSS}}{n-p},
\qquad
h^*=x^{*T}(X^TX)^{-1}x^*.
$$
Then an exact $(1-\alpha)$ prediction interval is
$$
x^{*T}\widehat\beta
\mathbin\pm t_{n-p,1-\alpha/2}s\sqrt{1+h^*}.
$$
The additional one inside the square root is the future observation's irreducible error variance; a confidence interval for its mean omits it.