Statistics & probability

Bayesian linear regression posterior calculator

Update a Gaussian prior on linear-model coefficients using observations with a known Gaussian noise variance.

Your numbers

Rows separated by semicolons; values by commas.
Rows separated by semicolons; values by commas.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Update a Gaussian prior on linear-model coefficients using observations with a known Gaussian noise variance. The calculator returns the joint coefficient posterior and a query prediction, distinguishing uncertainty in the latent mean from uncertainty in a new noisy response. Intercepts are explicit design columns, and the prior covariance remains visible.

THE FORMULAVn=(V0⁻¹+XᵀX/sigma²)⁻¹; mn=Vn(V0⁻¹m0+Xᵀy/sigma²).

A worked example

An intercept with prior N(0,1), known noise variance one and observations one and three has posterior precision three, posterior variance 1/3 and posterior mean 4/3. A new noisy observation has variance 1+1/3, unlike the latent mean variance 1/3.

Good to know

Known positive Gaussian noise variance; proper positive-definite Gaussian coefficient prior. Explicit intercept if desired; ≤6 coefficients/200 rows. No unknown-noise Student-t marginalization or automatic prior selection.

Specify the prior as a joint coefficient distribution

The prior mean has one entry for each design column, and the covariance has one row and column per coefficient. Diagonal entries describe prior variances; off-diagonal entries allow prior dependence between coefficients. A proper positive-definite covariance is required, rather than an unnormalized flat prior represented by an arbitrary huge number.

Coefficient units depend on the design. Changing a predictor from metres to centimetres changes the appropriate slope prior and its covariance with other coefficients. Copying the same numeric prior after a unit change imposes a different model. Record predictor scaling and coding before interpreting posterior shrinkage.

Gaussian posterior precision adds prior and data informationPrior precision: 1Data precision: 2Posterior variance = 1/(1+2) = 1/3Posterior mean = (1+3)/3 = 4/3
An intercept with prior N(0,1), known noise variance one and observations one and three has posterior precision three, posterior variance 1/3 and posterior mean 4/3. A new noisy observation has variance 1+1/3, unlike the latent mean variance 1/3. Diagram is schematic; labels specify the numerical values.

The Gaussian process regression calculator with prediction uncertainty uses an RBF kernel and reports latent and observation uncertainty at new inputs. This regression instead updates the coefficients of an explicitly entered linear design with known noise variance.

Use known noise variance as an actual assumption

Every response is modeled as its linear mean plus independent Gaussian noise with the same entered variance. The input is variance, not standard deviation. Unlike the prior covariance, it concerns observation error around the regression mean rather than uncertainty in the coefficient vector.

This page does not estimate that variance from residuals or integrate it out with an inverse-gamma prior. If the noise scale is unknown, substituting a guessed value gives a conditional calculation, not a full Bayesian treatment of unknown noise. Heavy tails and unequal observation variances likewise need a different likelihood.

Derive the precision update

Prior precision is the inverse prior covariance. Data add Xtranspose X divided by noise variance, so posterior covariance is the inverse of that precision sum. The posterior mean combines prior precision times prior mean with Xtranspose y divided by noise variance, multiplied by the new covariance.

This algebra explains why informative data reduce uncertainty in observed directions and why a proper prior can regularize a design that is weakly informative. It does not make every coefficient individually identified by the data. Inspect the posterior covariance and compare it with the prior rather than describing a stable numeric inverse as proof of strong evidence.

Calculate the intercept example directly

The default design has two rows of one, responses one and three, prior mean zero and prior variance one. With known observation variance one, posterior precision is one plus two, giving variance one third. The information-weighted response sum is four, so posterior mean is four thirds.

A query row of one therefore has latent mean four thirds and latent variance one third. Predicting a new noisy response adds the observation variance one, giving predictive variance four thirds. The two variances refer to different random objects even though their predictive mean is the same.

Build the query in the same design coordinates

If the design includes an intercept column, the query must include its corresponding one. If a categorical predictor uses indicator coding, the query must use the same reference and indicator structure. The calculator does not infer a raw feature-to-design transformation from column values.

The query mean is its row times the posterior mean vector, and latent variance is the quadratic form of that row with posterior covariance. Extrapolated queries can have large uncertainty, but a strongly informative prior may also dominate them. A plausible-looking prediction far from observed designs can therefore be prior-driven rather than independently supported.

Compare with penalized estimates carefully

Certain Gaussian-prior posterior means correspond algebraically to ridge-like point estimates under aligned likelihood scaling and prior conventions. That does not make the full outputs interchangeable. This form returns covariance and predictive distributions under a probabilistic model, whereas a penalized coefficient fit need not provide those quantities.

The intercept is not automatically excluded from the prior or added by the calculator. Supply every coefficient, including an intercept if wanted, with its explicit prior. A comparison using an unpenalized intercept in one fit and a strongly constrained intercept in the other is comparing different assumptions, not checking the same formula.

Interpret posterior uncertainty within the model

A Gaussian credible interval can be constructed from a posterior marginal variance, but its probability statement conditions on the prior, likelihood, noise variance and entered design. It is not a design-free guarantee of future coverage. The page does not perform model comparison, automatic prior selection or causal adjustment.

Check prior sensitivity and whether observations are plausibly independent with common variance. Repeated measurements and grouped data can require correlated errors. A converged matrix calculation cannot detect every such study-design problem. Use the posterior as a transparent update of specified assumptions and retain those assumptions with any reported coefficient or forecast.

A few questions, answered

Does the form add an intercept?

No. Include a column of ones and its prior entry if an intercept is wanted.

Is the noise variance estimated?

No. It is treated as known. Unknown-noise Bayesian regression requires a different posterior calculation.

Why are there two query variances?

Latent variance concerns the underlying linear mean. A new noisy response also includes observation variance.

Can prior covariance include off-diagonal entries?

Yes, provided it is positive definite. They express prior dependence between coefficients.

Find your calculator

Start typing to explore the library.