Skip to content
Prev 4167 / 5636 Next

[R-meta] Separate tau for each subgroup in mixed-effect models

This has also been possible with the rma.mv() function:

https://www.metafor-project.org/doku.php/tips:comp_two_independent_estimates#meta-regression_with_all_studies_but_different_amounts_of_residual_heterogeneity

So, actually, there are three different ways one can do this:

1) Fit separate RE models within subgroups.

dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)

res1 <- list(rma(yi, vi, data=dat, subset=alloc=="alternate"),
             rma(yi, vi, data=dat, subset=alloc=="random"),
             rma(yi, vi, data=dat, subset=alloc=="systematic"))

dat.comp <- data.frame(meta     = c("alternate","random","systematic"), 
                       estimate = sapply(res1, coef),
                       stderror = sqrt(sapply(res1, vcov)),
                       tau2     = sapply(res1, \(x) x$tau2))
dat.comp <- dfround(dat.comp, 4)
dat.comp

2) Fit an rma.mv() model with a random effects structure that allows tau^2 to differ across groups.

res2 <- rma.mv(yi, vi, mods = ~ 0 + alloc, random = ~ alloc | trial, struct="DIAG", data=dat)
res2

3) Use a location-scale model with a categorical scale variable.

res3 <- rma(yi, vi, mods = ~ 0 + alloc, scale = ~ 0 + alloc, data=dat)
res3
predict(res3, newscale=diag(3), transf=exp)

Instead of using the (default) log link, we can also use an identity link to fit this model:

res4 <- rma(yi, vi, mods = ~ 0 + alloc, scale = ~ 0 + alloc, data=dat, link="identity")
res4

Compare the log likelihoods:

sum(sapply(res1, logLik)) # add up the three log likelihoods
logLik(res2)
logLik(res3)
logLik(res4)

The results match up nicely, as they should.[1] This is in fact a nice confirmation that the underlying code - which is rather different for these different approaches - works as intended.

[1] You might actually see minor discrepancies here and there. They can arise due to differences in how these models are fitted and the optimization routines used.

Best,
Wolfgang