- Introduced by
- Gelman, Jakulin, Pittau & Su (weakly-informative prior framework, 2008)
- Year
- 2008
- Type
- Bayesian classification model
What does it do?
Bayesian logistic regression applies Bayesian inference to a logistic (sigmoid) likelihood for a binary outcome.
It places a prior distribution over the coefficients and combines that prior with the data, giving a posterior distribution for each coefficient and for predicted class probabilities. It is most useful where maximum likelihood estimates are unstable, such as small samples, rare events, or complete separation. The default weakly informative prior commonly used with it was proposed by Gelman, Jakulin, Pittau and Su (2008).
The intuition behind the method
Ordinary logistic regression searches for the single set of coefficients that best fits the data. Bayesian logistic regression instead asks which coefficient values are plausible given both a prior belief and the observed outcomes, and the answer is a distribution. When events are few or the classes separate perfectly, the prior acts as a regulariser that keeps the coefficients finite, whereas maximum likelihood estimates can diverge or fail to converge.
History
Logistic regression is a generalized linear model that has traditionally been fitted by maximum likelihood. The Bayesian version is typically fitted with MCMC or variational methods. Gelman, Jakulin, Pittau and Su (2008) proposed a default weakly informative prior for classical logistic and other regression models. They recommend scaling non-binary predictors to mean 0 and standard deviation 0.5, and then placing a Cauchy prior with centre 0 and scale 2.5 on the coefficients. That prior is the main reference point for the weakly informative approach used in this method.
When to use it
Choose Bayesian logistic regression when the outcome is binary and maximum likelihood estimation is unreliable for the data at hand: when events are rare, when the classes separate completely or quasi-completely so that maximum likelihood estimates become infinite, or when the sample is small, so that the data constrain the coefficients weakly and the prior has a visible role (in that case a prior sensitivity analysis is essential). It also suits analyses where prior information from earlier work should be formally included, or where the full posterior uncertainty of the coefficients and predicted probabilities matters for the decision. Do not choose it simply for its own sake: with a large sample and no separation, frequentist logistic regression gives very similar point estimates at much lower computational cost. The method as specified here models a binary outcome only.
Limitations and considerations
- When the sample is small or events are few, the posterior can be dominated by the prior and the data contribute little, so results depend heavily on the prior.
- If a prior sensitivity analysis shows the posterior moving substantially under reasonable alternative priors, the advantage over maximum likelihood is much weaker and the conclusions should be reported as prior-dependent.
- Sampling by MCMC is far more computationally demanding than a single maximum likelihood optimisation, and convergence must be verified before results are interpreted.
- For large, well-separated samples with no special requirements, frequentist logistic regression is usually sufficient and considerably faster.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Stays stable under complete or quasi-complete separation, because the prior keeps the coefficient estimates finite where maximum likelihood diverges.
- Returns a posterior distribution for every coefficient and predicted probability, so credible intervals come from the posterior rather than from asymptotic approximations.
- Prior information can be formally incorporated, which can help in rare-event or small-sample settings.
- Posterior predictive checks give a direct way to assess whether the fitted model reproduces the observed data, beyond a single goodness-of-fit statistic.
Applications
- Models of voting preferences, one of the applications illustrated by Gelman et al. (2008).
- Small bioassay experiments, where separation and sparse data can make maximum likelihood unreliable.
- Imputation models for public health data. Gelman et al. (2008) illustrate the approach with such a data set and note that the default prior can be useful in automated procedures such as chained equations for missing-data imputation.
- Models with rare outcomes, where prior information from earlier studies can be formally included in the analysis.
- Binary classification tasks in which posterior probabilities with uncertainty are needed for downstream decisions.
How it works
How it works
Bayes' rule combines the data likelihood with a prior over the coefficients to give the posterior. The prior encodes which coefficient values are plausible before the outcomes are seen. Gelman et al. (2008) propose a Cauchy prior with centre 0 and scale 2.5 on the coefficients, after scaling non-binary predictors to mean 0 and standard deviation 0.5; they present this as a weakly informative default that still returns estimates under complete separation.
Formula
p(\boldsymbol{\beta}\mid \mathbf{y}) \propto p(\mathbf{y}\mid\boldsymbol{\beta})\,p(\boldsymbol{\beta})For each observation, the probability that the outcome equals 1 is the sigmoid of the linear predictor x_i^T β. Each coefficient β_j gives the change in log-odds of the outcome for a one-unit change in predictor x_j. A prior is placed on the whole coefficient vector β. Because no closed-form conjugate prior exists for this likelihood, the posterior generally has to be sampled or approximated.
Formula
p(y_i=1\mid\mathbf{x}_i,\boldsymbol{\beta}) = \sigma(\mathbf{x}_i^\top\boldsymbol{\beta}) = \frac{1}{1+e^{-\mathbf{x}_i^\top\boldsymbol{\beta}}}Multiplying the logistic likelihood across all observations by the prior gives the joint posterior over β. This posterior has no analytic closed form, so it is usually explored with Markov chain Monte Carlo, for example the No-U-Turn Sampler (NUTS), a variant of Hamiltonian Monte Carlo. Convergence is checked with R-hat, effective sample size and trace plots, and posterior predictive checks compare simulated data with the observed data. Posterior means and 95% credible intervals are then computed from the draws.
Formula
p(\boldsymbol{\beta}\mid\mathbf{y}) \propto \prod_{i=1}^{n} \sigma(\mathbf{x}_i^\top\boldsymbol{\beta})^{y_i}\bigl[1-\sigma(\mathbf{x}_i^\top\boldsymbol{\beta})\bigr]^{1-y_i}\cdot p(\boldsymbol{\beta})Common pitfalls
- Reporting posterior summaries without first checking convergence. Inspect R-hat (the page's target is below 1.01), effective sample size and trace plots for every parameter.
- Using a prior that is more informative than intended, which can overpower the likelihood, especially in small samples. Run a prior sensitivity analysis with reasonable alternatives.
- Skipping posterior predictive checks, which are the main tool here for detecting systematic misfit between model and data.
- Reading a 95% credible interval as a frequentist confidence interval. The two have different interpretations and should not be conflated.
Frequently asked questions
What is complete separation and why does it matter?
Complete separation occurs when a predictor, or a combination of predictors, perfectly predicts the outcome in the sample: every case above some threshold has y = 1 and every case below has y = 0. Maximum likelihood responds by pushing the coefficient toward infinity, because the likelihood keeps increasing as the slope grows. A prior keeps the estimate finite. Gelman et al. (2008) note that their default prior always gives an answer, even under complete separation, which is one practical reason to use the Bayesian version.
How do I choose the prior for the coefficients?
Gelman et al. (2008) recommend scaling non-binary predictors to mean 0 and standard deviation 0.5, then placing a Cauchy prior with centre 0 and scale 2.5 on the coefficients. This is weakly informative: it gives little prior weight to very large coefficients while remaining diffuse enough for the data to dominate when the sample is adequate. If you have genuine prior information from earlier studies, encode it directly. Whatever prior you use, run a sensitivity analysis and report if the posterior shifts substantially under reasonable alternatives.
How do I know if my MCMC chains have converged?
Check R-hat for every parameter; values below 1.01 indicate the chains have mixed well. Check the effective sample size and make sure there are enough effective draws for stable posterior summaries. Inspect trace plots for stationarity and good mixing. If any diagnostic fails, run longer chains, increase warm-up, or reparameterise the model before interpreting the results.
How is Bayesian logistic regression different from regularised logistic regression (e.g. Lasso or Ridge)?
Penalised frequentist logistic regression adds a penalty to the log-likelihood and returns a single penalised point estimate. The penalty can be read as corresponding to a prior, but the output is still a point. Bayesian logistic regression returns the full posterior for every coefficient, so you see both the estimate and its uncertainty. Credible intervals, posterior predictive checks and model comparison are natural outputs of the Bayesian approach, whereas they do not arise automatically from penalised maximum likelihood.
Related methods
Sources
Gelman, A., Jakulin, A., Pittau, M. G. & Su, Y.-S. (2008). A Weakly Informative Default Prior Distribution for Logistic and Other Regression Models. Annals of Applied Statistics, 2(4), 1360–1383.
Open DOI reference