R and JAGS code accompanying my ICPSR summer program course on Applied Bayesian Modeling. See http://www.jkarreth.net/bayes-icpsr.html for more information. Please feel free to fork and develop any code you see in this repository. If you notice a problem or have a question, please email me at jkarreth@albany.edu and/or create an issue with the respective file.
- angell.instructions.R: code for a Bayesian linear regression model, using the Angell data from John Fox's R and S-PLUS Companion to Applied Regression in R using R2jags. This example contains code for data preparation, model fitting, and diagnostics.
- angell.jags.zip: code for the same model directly in JAGS from the Terminal and analyze the output using the
coda
package in R. - beer.instructions.R: code for a Bayesian ordered logit model, using data on beer ratings
- econvote.instructions.R: code for a Bayesian multinomial logit model, using Austrian voting data.
- legislators.instructions.R: code for Simon Jackman's Legislators example using R2jags. [Bayesian IRT model]
- pumps.instructions.R: code for the Pumps demo from the WinBUGS examples folder using R2jags. [Conjugate gamma-Poisson hierarchical model]
- rats.instructions.R: code for the Rats demo from the WinBUGS examples folder using R2jags. [Normal hierarchical model]
- wvs.instructions.R: Linear model with group-level coefficients using an old subsample of World Values Survey.
- mlm.state.instructions.R: Step-by-step instructions to set up hierarchical data in R and fit a multilevel logit model using R2Jags, following the example in chapter 17 of Gelman and Hill's Data Analysis Using Regression and Multilevel/Hierarchical Models. Data: polls.subset.merged.dta, polls.subset.JK.dta, presvote.dta.
- diagnostics.R:
This script shows a variety of ways to obtain diagnostics
(traceplots, density plots, BGR, etc.) of JAGS/MCMC objects in R
using the
coda
,superdiag
,ggmcmc
, andmcmcplots
packages.
- regression.table.R: example code to easily export JAGS/BUGS results to LaTeX or HTML. Based on my mcmctab function.
- regression.dotplot.R: example code to easily make regression coefficient plots from JAGS/BUGS results.
- Posterior-Plots.R: a function written by Kevin Reuning (participant in the 2015 Applied Bayes workshop at ICPSR) to create a coefficient dot plot with added posterior density.
- interaction.instructions.R: code to plot marginal effects from a Bayesian linear model with an interaction term across the range of a moderating variable.
- limited.dep.vars.funcs.R: a set of functions written by Eric Dunford (participant in the 2015 Applied Bayes workshop at ICPSR) to calculate and visualize predicted probabilities from Bayesian logit or probit models for observed and simulated data.
- factor.dotplot.R: code to make a dot plot (with credible intervals) of a Bayesian factor score.