Archive for June, 2009


Simple OpenBUGS MR example

June 17, 2009

Below is some OpenBUGS code that I created that models income as a function of age, race, and educational status. This is a simple MR example and can easily be replicated in R with the lm() function.

## OpenBUGS Model
for( i in 1:6641) {
income[i] ~ dnorm(mu[i], tau)
mu[i] <- beta0 + beta1*educ[i] + beta2*age[i] + beta3*race[i]
## Priors
#beta0 ~ dflat()
#beta1 ~ dflat()
#beta2 ~ dflat()
#beta3 ~ dflat()
## Hypothesized Priors, deduced by "peaking"
beta0 ~ dnorm(3, 0.1)
beta1 ~ dnorm(0.3, 0.1)
beta2 ~ dnorm(0.01,0.5)
beta3 ~ dnorm(0, 0.1)
tau ~ dgamma(0.1,0.1)
sigma <- 1/sqrt(tau)
## Initial values
list(beta0 = 0, beta1 = 1, beta2 = 1, beta3 = 1, tau = 1)

You can get the data and a file that contains the model and the initial values here. This is example is entirely didactic, comes with no warranty, and is entirely intended to help get folks up and running in *BUGS.

The most interesting bits: With this large sample size (n ~ 6000), the priors seem to be washed away by the data and the high similarity between the results from the Bayesian and the frequentist analyses (run via lm in R).


OpenBUGS and WinBUGS on Mac OS X

June 15, 2009

I haven’t found a really good how-to for getting OpenBUGS and WinBUGS up and running on Mac OS X, so I thought I’d create a little how-to. Setting up these programs is super easy but requires MacPorts and wine .

First, you need to have the Xcode developer tools installed. Go to Apple, create an account, and download them.

Second, install MacPorts (get it here for 10.5) by clicking the *.dmg file.

Third, open a terminal and type:

sudo port install wine

This will take about 20 minutes to compile wine and all its dependencies.

Fourth, download the WinBUGS zip file here and the OpenBUGS zip file here .

Fifth, unzip the WinBUGS file by double clicking on it and it will create a folder called WinBUGS14. Move this to Applications. For OpenBUGS, I had to create a folder called OpenBUGS, move the zip file there, open up a terminal, and type unzip (double clicking this file did not work thus I fired up a terminal). This folder I then moved to Applications.

Sixth, to start WinBUGS open a terminal and type the following:

cd /Applications/WinBUGS14
wine WinBUGS14.exe

For OpenBUGS, open a terminal and type the following (assuming you created a folder named OpenBUGS with all the file from the files in them):

cd /Applications/OpenBUGS
wine winbugs.exe

Everything seems to work fine. The only thing I’ve noticed is that the fonts are not as nice in wine as they are in Windows and in WinBUGS some of the documentation doesn’t work properly (e.g. clicking on links does nothing), whereas in OpenBUGS they work flawlessly.

Please leave comments if this works/doesn’t work for you.

EDIT June 1st 2010
I see that lots of people have been coming here to learn how to install OpenBUGS and WinBUGS on Mac OS X. What I would like to do is to encourage you to use JAGS and rjags instead of *BUGS. It is very similar to *BUGS, can do nearly the same things as *BUGS, and is opensource. So please consider JAGS instead of *BUGS.


IES 2009 Poster Presentation

June 11, 2009

This past Monday I presented a poster on my research at the Institute of Education Sciences . It examined the influence of risk on reading and math achievement with a specific focus on treating risk as a dynamic and static covariate. Analysis was performed with the lme4 package in R and graphs were created in ggplot2 . Model selection was done with the BIC. The static models overwhelmingly beat the dynamic models. Click on the picture to download a PDF of the poster. Feedback is welcomed.


Finally, this blog will now be updated at least weekly with more comprehensive notes on Bayesian analysis, R and WinBUGS code.