The fundamental abstractions underlying BUGS and Stan as probabilistic programming languages

Probabilistic programming languages I think of BUGS and Stan as probabilistic programming languages because their variables may be used to denote random variables, with function application doing the right thing in terms of propagating randomness (usually encoding uncertainty in a … Continue reading

Some (statistical) stories about BUGS

Hey, I don’t think I ever posted a link to this. It’s a discussion in the journal Statistics in Medicine of an article by David Lunn, David Spielhalter, Andrew Thomas ,and Nicky Best. (Sorry but I can’t find the Lunn et al. article online, or I’d link to it.) Anyway, here’s my discussion. Once upon a time . . .

I first saw BUGS in a demonstration version at a conference in 1991, but I didn’t take it seriously until over a decade later, when I found that some of my Ph.D. students in political science were using Bugs to fit their models. It turned out that Bugs’s modeling language was ideal for students who wanted to fit complex models but didn’t have a full grasp of the mathematics of likelihood functions, let alone Bayesian inference and integration. I also learned that the modular structure of BUGS was a great way for students, and researchers in general, to think more about modeling and less about deciding which conventional structure should be fit to data.

Since then, my enthusiasm for BUGS has waxed and waned, depending on what sorts of problems I was working on. For example, in our study of income and voting in U.S. states [1], my colleagues fit all our models in BUGS. Meanwhile we kept running into difficulty when we tried to expand our model in different ways, most notably when going from varying-intercept multilevel regressions, to varying-intercept, varying-slope regressions, to models with more than two varying coefficients per group. Around this time I discovered lmer [2], a function in R which fits multilevel linear and generalized linear models allowing for varying intercepts and slopes. The lmer function can have convergence problems and does not account for uncertainty in the variance parameters, but it is faster than Bugs and in many cases more reliable-so much so that Jennifer Hill and I retooled our book on multilevel models to foreground lmer and de-emphasize Bugs, using the latter more as a way of illustrating models than as a practical tool.

What does BUGS do best and what does it do worst?

Continue reading

Bugs sucks

I programmed a Bugs model (see below) and got this horrible and useless error message: Bugs opened a “Trap: incompatible copy” window, and there was nothing in the log window but this:

display(log)
check(C:\DOCUME~1\ANDREW~1\LOCALS~1\Temp\RtmpMCdEbN/pewpoststrat2.bug.txt)

No syntax error, no nothing. My first thought, of course, was that there was something wrong with the default directory, but when I copied the “schools” example over, it worked fine. So I went through the laborious process of debugging, stripping down the code until I could get it to run and then gradually adding back lines until it crashed. I still couldn’t figure out what was wrong so I brought Matt over and he figured it out at a glance.

Here was the original code: Continue reading

Fitting multilevel models using packages other than R and Bugs

Our new book on regression and multilevel models is written using R and Bugs. But we’d also like, in an appendix, to quickly show how to fit multilevel models using other software, including Stata, Sas, Spss, MLWin, and HLM (and others?). We’d really appreciate your help in getting sample code for these packages.

We’ve set up five simple examples. I’ll give them below, along with the calls in R that would be used to fit the models. We’re looking for the comparable commands in the other languages. We don’t actually need anyone to fit the models, just to give the code. This should be helpful for students who will be learning from our book using other software platforms. Continue reading