APPLIED INTRODUCTION TO BAYESIAN DATA ANALYSIS
Copenhagen Graduate School of Social Sciences
January 5-7, 2015
Please note: This page is archived from the last time I taught this course.
For materials for current courses, please go to my teaching page.
Welcome to the website for my 3-day workshop on Bayesian Data Analysis at the University of Copenhagen, January 5-7, 2015. This page contains materials for workshop participants and additional resources for Bayesian data analysis.
Workshop outline
The outline for this workshop is available here.Setup & before we meet
Before our first meeting, please complete a couple of steps to prepare for the workshop:- Complete my brief survey to give me a rough idea of the background of all workshop participants. Please email your answers by January 1.
- Have a look at my "(very basic) R tutorial" and install R and RStudio on your computer.
- Have a look at sections 1-3 of my tutorial "Using JAGS via R" and install JAGS and the packages mentioned in section 3 on your computer.
Tutorials
The tutorials below contain information and code to .Slides and source code
Slides for each workshop unit and the source code I used to create them are posted below. Slides are posted as .pdf files, and the R code for all applications is posted in .R files.Modeling exercises
This file provides some (voluntary) exercises for all topics discussed in the workshop.Modeling examples
The R scripts below contain fully working examples of Bayesian regression models for different types of outcome variables. All models are fit using JAGS.- angell.instructions.R - fit 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 - fit the same model directly in JAGS from the Terminal and analyze the output using the
coda
andboa
packages in R. - beer.instructions.R - fit a Bayesian ordered logit model, using the Beer data in R using R2jags
- econvote.instructions.R - fit a Bayesian multinomial logit model, using Austrian voting data in R using R2jags. [Multinomial logit model]
- undervote.instructions.R - fit Simon Jackman's Undervote example in R using R2jags [Difference of two proportions]
- turnout.instructions.R - fit (a slightly modified version of) Simon Jackman's Turnout example in R using R2jags. [Logit model]
- legislators.instructions.R - fit Simon Jackman's Legislators example in R using R2jags. [Bayesian IRT model]
- pumps.instructions.R - fit the Pumps demo from the WinBUGS examples folder in R using R2jags [Conjugate gamma-Poisson hierarchical model]
- rats.instructions.R - fit the Rats demo from the WinBUGS examples folder in R 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. Data: polls.subset.merged.dta, polls.subset.JK.dta, presvote.dta.
Diagnostics
The bottom of 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, ggplotmcmc, and mcmcplots packages.Model presentation
- regression.table.R - R code to easily export JAGS/BUGS results to LaTeX or HTML.
- regression.dotplot.R - R code to easily make regression coefficient plots from JAGS/BUGS results.
- interaction.instructions.R - R code to plot marginal effects from a Bayesian linear model with an interaction term across the range of a moderating variable.
- logit.pp.plot.instructions.R - R code to plot predicted probabilities from a Bayesian logit model over a simulated range of values for an explanatory variable of interest.
- ologit.pp.plot.instructions.R - R code to plot predicted probabilities over the simulated range of explanatory variables after a Bayesian ordered (or multinomial) logit model. Partially based on code by Dave Armstrong (UW-Milwaukee).
- factor.dotplot.R - R code to make a dot plot (with credible intervals) of a Bayesian factor score.