BRMS continues its streak

As you probably know, I’m a big fan of R’s brms package, available from CRAN. In case you haven’t heard of it, brms is an R package by Paul-Christian Buerkner that implements Bayesian regression of all types using an extension of R’s formula specification that will be familiar to users of lm, glm, and lmer. Under the hood, it translates the formula into Stan code, Stan translates this to C++, your system’s C++ compiler is used to compile the result and it’s run.

screen-shot-2016-11-20-at-4-38-05-pm

brms is impressive in its own right. But also impressive is how it continues to add capabilities and the breadth of Buerkner’s vision for it. I last posted something way back on version 0.8, when brms gained the ability to do non-linear regression, but now we’re up to version 1.1, with 1.2 around the corner. What’s been added since 0.8, you may ask? Here are a few highlights:

You can now define functions in Stan, using stan_funs and can use them in your formula or use them like a native R function (via expose_functions), which is pretty exciting. A huge addition is gam-style smoothers, allowing us to implement GAMMs (Generalized Additive Mixture Models), including spatial GAMMs (via MRF smoothers). Interval censoring has been added to the already-existing left and right censoring. You can use monotonic effects in ordinal regression, and both monotonic and cse (category-specific) effects can be used at the individual or group levels. It now supports distributional regression models, allowing modeling of things like the heterogeneity of variances. There are many efficiency improvements, and you can now use IDs to specify that multiple groups share the same group-level effects across formulas. The von mises family has been added to allow for circular regression. (I’ve had some difficulty making it work, I have to admit.) Last, the graphing gets better and better — it was also updated to work with ggplot2 version 2.2 — and many of the plots will soon (brms 1.2) use package bayesplot.

Buerkner’s To Do list includes items like CAR (Conditional Auto Regression) models which are state-of-the-art for spatial regression, mixture models, and errors-in-variables models. Yeah, he doesn’t rest on his laurels.

The flexibility of brms formulas allows you to create sophisticated models easily. For example, using cens and the Weibull family allows you to create (AFT) survival models. Add in a random effect and you have a frailty model — no need to learn something dramatically new. If you reach brms limits, you may be able to dip your toe into Stan and include a Stan function via stan_funs. If that’s not good enough, you can extract the Stan model, via stan_model and then modify it and use the rstan package and go full-fledged Stan. (brms implements much simpler, more human-like Stan models than rstanarm, which makes it much more practical to build on a reliable base of code.)

But you will use brms for a long time before you need to delve into Stan. You can do lm-style models, you can add a family to do GLMs (including logistic regression, categorical or ordinal logistic regression, Poisson, Lognormal, zero-inflated Negative Binomial, etc), you can add in random effects to create a mixed-effects model, you can add in smoothers to create GAMs, you can add smoothers and random effects to create GAMMs, you can handle censored variables and use the appropriate family (Weibull, etc) to create survival models, and you could take your survival model and add a random effect to get a frailty model. All without doing anything radically different from specifying an lmer model.

Check out brms on CRAN!

Advertisements

2 thoughts on “BRMS continues its streak

  1. Pingback: mixed effect models | social by selection

  2. Thanks Wayne for this awesome post about what is new! I have just a minor comment: monotonic effects can be applied in all kinds of families (essentially they can be thought of as “ordinal” predictors), whereas category specific effects are the ones that are only meaningful for ordinal families.

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