[R-sig-ME] Update to 'metafor' Package

Viechtbauer Wolfgang (STAT) wolfgang.viechtbauer at maastrichtuniversity.nl
Thu Oct 17 16:07:37 CEST 2013


Dear "Mixed Modelers",

I am usually not too crazy about posts regarding package updates (those who use certain packages find out about those updates anyway), but once in a while this can be useful when those updates are of a more substantive nature than some bug fixes and slight improvements and when those updates may be of interest to a larger audience. With that in mind, I wanted to let the group know that I recently updated the 'metafor' package (a package for conducting meta-analyses with R). Since the usual meta-analytic models are in fact mixed-effects models, I figured that this may be of interest to at least some readers.

In the recent update, I added functionality for fitting multilevel/multivariate meta-analytic models. This was on my to-do list for longer than I like to admit, and the code for this had been sitting around for a long time, but it took quite some effort to properly test and document it. By the way, during that process, I gained entirely new levels of appreciation for packages like 'nlme' and 'lme4', which are in a league of their own, given their capabilities, flexibility, and stableness.

At any rate, this functionality is finally available, which makes it possible to fit a wide variety of rather complex meta-analytic models. This includes multivariate models for dependent outcomes (e.g., resulting from multiple assessments of the same response variable with different instruments, multiple assessments of different response variables, or multiple assessments of the response variable over time), models for network meta-analyses (also called multitreatment comparison meta-analyses), phylogenetic meta-analyses (i.e., meta-analyses that account for the shared phylogenetic history among the organisms studied), and in general models that account for correlation in outcomes induced by a multilevel structure in the data (e.g., multiple effects derived from the same paper, lab, research group, or species may be more similar to each other than effects derived from different papers, labs, research groups, or species).

In principle, one can also (ab)use this functionality for fitting mixed-effects model to primary data using two-step procedures. I'll give a simple example using the Orthodont data:

library(nlme)
library(metafor)
library(Matrix)

data(Orthodont)

### "center" the age variable
Orthodont$age <- Orthodont$age - 8

### standard random intercepts and slopes mixed-effects model
res1 <- lme(distance ~ age, random = ~ age | Subject, data=Orthodont)

### fit regression model per person
res.list <- lmList(distance ~ age, data=Orthodont)

### obtain coefficients and var-cov matrices thereof
b <- lapply(res.list, coef)
V <- lapply(res.list, vcov)

### dummy for coefficients and subject id variable
x    <- rep(c("Int","Slope"), length(b))
subj <- rep(names(b), each=2)

### create one long vector with the coefficients and corresponding var-cov matrix
b <- unlist(b)
V <- as.matrix(bdiag(V))

### now conduct a meta-analysis with the coefficients using an unstructed var-cov matrix for the true outcomes (i.e., coefficients)
res2 <- rma.mv(b ~ x - 1, V, random = ~ x | subj, struct="UN")

summary(res1)
summary(res2)

The results are quite similar. I would not recommend to do something like that in general, but it nicely illustrates how such a two-stage procedure (fit the "level 1 model" per person, then aggregate the coefficients) is quite similar to what the mixed-effects model does. In teaching about mixed-effects models, I have found it helpful to show this correspondence. I should point out though that I wrote rma.mv() for meta-analytic applications, where the total number of observed outcomes is typically quite small. I therefore spent little (read: no) effort on making it efficient for large sample sizes. So, if you feed 1000s of effects to it, you can make a pot of coffee (and probably consume it) while you wait for the model to converge.

You can read more about the metafor package on the package website at:

http://www.metafor-project.org/

On the website, I also provide some analysis examples, illustrating how various methods and models described in the meta-analytic literature can be replicated using the package:

http://www.metafor-project.org/doku.php/analyses

I'll keep expanding on this as I find the time. For the ecologists on this list -- I'll add a phylogenetic meta-analysis example as soon as I get my hands on an illustrative dataset. The package will also get another update in the near future, allowing for autoregressive structures in the true effects (useful when there are multiple assessments of an effect over time).

Anyway, I hope this was of interest to at least some readers. Now back to your regular scheduled program on mixed-effects models ...

Best,
Wolfgang

--   
Wolfgang Viechtbauer, Ph.D., Statistician   
Department of Psychiatry and Psychology   
School for Mental Health and Neuroscience   
Faculty of Health, Medicine, and Life Sciences   
Maastricht University, P.O. Box 616 (VIJV1)   
6200 MD Maastricht, The Netherlands   
+31 (43) 388-4170 | http://www.wvbauer.com   



More information about the R-sig-mixed-models mailing list