Bayesian statistics

Going full Bayesian with mixed effects regression models

Posted on Updated on

Thanks to some recently developed tools, it’s becoming very convenient to do full Bayesian inference for generalized linear mixed-effects models. First, Andrew Gelman et al. have developed Stan, a general-purpose sampler (like BUGS/JAGS) with a nice R interface which samples from models with correlated parameters much more efficiently than BUGS/JAGS. Second, Richard McElreath has written glmer2stan, an R package that essentially provides a drop-in replacement for the lmer command that runs Stan on a generalized linear mixed-effects model specified with a lme4-style model formula.

This means that, in many cases, you simply simply replace calls to (g)lmer() with calls to glmer2stan():

library(glmer2stan)
library(lme4)
lmer.fit <- glmer(accuracy ~ (1|item) + (1+condition|subject) + condition, 
                  data=data, family='binomial')
summary(lmer.fit)
library(glmer2stan)
library(rstan)
stan.fit <- glmer2stan(accuracy ~ (1|item) + (1+condition|subject) + condition, 
                       data=data, family='binomial')
stanmer(stan.fit)

There’s the added benefit that you get a sample from the full, joint posterior distribution of the model parameters

Read on for more about the advantage of this approach and how to use it.

Rutgers-stimulated thoughts/tools

Posted on

I just came back from a wonderful visit at Rutgers (RuCCS to be precise). I had a lot of interesting conversations, some of which directly or indirectly brought up some tools that I wanted to mention here.

  • So, first I was treated to a great presentation of OT Workplace (by Alan Prince and Bruce Tesar), a cool and relatively intuitive environment that lets you investigate the consequences of a set of proposed OT constraints (this is brave old categorical OT, nuttin’ with stochastics or Harmonic Grammars etc.). There are to many functions to describe them here (including, of course, factorial typologies), but if you’re into Optimality Theory, have a look.  The above link goes straight to the excel sheet with the documentation and scripts (VBA-based). If it’s broken just check on Alan’s page.
  • Although this didn’t really come up during conversations, I just saw this nice MatLab package by Randy Gallistel on a Bayesian approach to Proving The Null (hypothesis). Actually you can also enter data for an analysis online (though it might be helpful to first read the page linked in bold above).

So, thanks to Jane and Patty for organizing this visit and to everyone for the good conversations.