»  Home »  Stata News »  Vol 32 No 3 »  Spotlight: bayes:logistic
The Stata News

«Back to main page

Bayesian logistic models and Cauchy priors—Why and how

Fitting Bayesian regression models is now truly easy in Stata with the bayes prefix. For example, we can use the classic iris dataset (Fisher 1936) to fit a logistic regression of whether an iris is of the virginica class based on sepal length, sepal width, petal length, and petal width.

. logit virginica sepallen sepalwid petallen petalwid

Fitting this as a Bayesian model is as easy as adding the bayes prefix:

. bayes: logit virginica sepallen sepalwid petallen petalwid

All regression parameters use a relatively noninformative normal prior. Gelman et al. (2008) make a good case that a Cauchy prior is preferred for logistic regression. Let's consider the posterior distributions from our bayes estimates.


Note that most of the distributions are fairly heavily skewed so that the mean and median of the parameter estimates are quite different. In addition, much of the mass of each distribution is unrealistically far from zero when considering the logit scale.

Cauchy priors with appropriately chosen scale parameters handle the skewness and extreme values better than normal priors. To fit the model using Cauchy priors, we type

. bayes, prior({virginica:_cons}, cauchy(0, 10))
         prior({virginica:virginica sepallen sepalwid petallen petalwid}, cauchy(0, 2.5)):
         logit virginica sepallen sepalwid petallen petalwid

I may have raised as many questions as I have answered. You can read much more about Cauchy priors and even learn about Bayesian predictions in my blog entry.


Fisher, R. A. 1936. The use of multiple measurements in taxonomic problems. Annals of Eugenics 7: 179–188.

Gelman, A., A. Jakulin, M. G. Pittau, and Y.-S. Su. 2008. A weakly informative default prior distribution for logistic and other regression models. Annals of Applied Statistics 2: 1360–1383.

— Nikolay Balov
Principal Statistician and Software Developer

«Back to main page





The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ YouTube
© Copyright 1996–2018 StataCorp LLC   •   Terms of use   •   Privacy   •   Contact us