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).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: