[R] Main-effect of categorical variables in meta-analysis (metafor)

Viechtbauer Wolfgang (STAT) wolfgang.viechtbauer at maastrichtuniversity.nl
Fri Aug 5 12:30:13 CEST 2011


Dear Jokel,

If a moderator has 4 levels, then you need 3 dummy variables (one of the levels will become your "reference" level, so you do not need a dummy for that one). You can do the dummy-coding yourself or let R handle it. For example, if the moderator is called "catmod", then:

rma(yi, vi, mods = ~ factor(catmod), data=some.data.frame)

should do the trick (you do not need factor() if catmod is already a factor variable in the data frame). R will create the dummies for you. If you do not like which level is chosen as the reference level, then take a look at the relevel() function. In particular, 

rma(yi, vi, mods = ~ relevel(factor(catmod), ref = "reflevel"), data=some.data.frame)

will set the reference level to "reflevel".

If you have two categorical moderators, let's call them catmod1 and catmod2, then:

res0 <- rma(yi, vi, mods = ~ factor(catmod1) + factor(catmod2), data=some.data.frame)

will give you a model without and

res1 <- rma(yi, vi, mods = ~ factor(catmod1) * factor(catmod2), data=some.data.frame)

will give you a model with the interaction between the two factors. In the latter model, you will get lots of coefficients for the interaction, each testing whether the difference between a particular catmod2 level and the reference catmod2 level differs across the levels of catmod1 (and vice-versa). To test whether the interaction is significant in general, you can either do a Wald-type test with:

rma(yi, vi, mods = ~ factor(catmod1)*factor(catmod2), data=some.data.frame, btt=X:Y)

where X is the number of the first "interaction coefficient" and Y is the number of the last "interaction coefficient" (so, these are indices to indicate which coefficients should be tested simultaneously). In the output, you will the results of this test under "Test of Moderators".

Alternatively, you can do a likelihood-ratio test with:

res0 <- rma(yi, vi, mods = ~ factor(catmod1) + factor(catmod2), data=some.data.frame, method="ML")
res1 <- rma(yi, vi, mods = ~ factor(catmod1) * factor(catmod2), data=some.data.frame, method="ML")
anova(res1, res0)

Note that you need to use ML-estimation when doing the LR-test.

Similar omnibus tests of several coefficients (full versus reduced model comparisons) can be done for the main effects.

An example with the BCG dataset:

data(dat.bcg)
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, append=TRUE)
dat$ablat.cat <- ifelse(dat$ablat > 30, "far", "close")

rma(yi, vi, mods = ~ factor(alloc) * factor(ablat.cat), data=dat, btt=5:6)

res0 <- rma(yi, vi, mods = ~ factor(alloc) + factor(ablat.cat), data=dat, method="ML")
res1 <- rma(yi, vi, mods = ~ factor(alloc) * factor(ablat.cat), data=dat, method="ML")
anova(res0, res1)

I hope this helps!

Best,

-- 
Wolfgang Viechtbauer 
Department of Psychiatry and Neuropsychology 
School for Mental Health and Neuroscience 
Maastricht University, P.O. Box 616 
6200 MD Maastricht, The Netherlands 
Tel: +31 (43) 368-5248 
Fax: +31 (43) 368-8689 
Web: http://www.wvbauer.com 


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Jokel Meyer
> Sent: Friday, August 05, 2011 10:45
> To: r-help at r-project.org
> Subject: [R] Main-effect of categorical variables in meta-analysis
> (metafor)
> 
> Dear R-experts!
> 
> In a meta-analysis (metafor) I would like to assess the effect of two
> categorical covariates (A & B) whereas they both have 4 levels.
> Is my understanding correct that this would require to dummy-code (0,1)
> each
> level of each covariate (A & B)?
> However I am interested in the main-effects and the interaction of these
> two
> covariates and the dummy-coding would only allow to detect the effect of
> one
> level of one factor. Would there be a way to assess main-effects and
> interactions (something like an meta-analysis-ANOVA)?
> 
> Many thanks,
> Jokel
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list