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

Viechtbauer, Wolfgang (NP) wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Thu Sep 1 10:18:06 CEST 2022

```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

>-----Original Message-----
>From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces using r-project.org] On
>Behalf Of James Pustejovsky
>Sent: Thursday, 01 September, 2022 2:06
>To: Arthur Albuquerque
>Cc: R meta
>Subject: Re: [R-meta] Separate tau for each subgroup in mixed-effect models
>
>Hi Arthur,
>
>Yes, these sorts of models are now supported in metafor::rma.uni(). For
>details, see
>https://wviechtb.github.io/metafor/reference/rma.uni.html#location-scale-models
>For a sub-group analysis with a categorical moderator called `mod`, the
>syntax would look something like
>rma.uni(yi = yi, sei = sei, mods = ~ mod, scale = ~ mod, data = dat, method
>= "REML")
>
>Best,
>James
>
>On Wed, Aug 31, 2022 at 6:43 PM Arthur Albuquerque <arthurcsirio using gmail.com>
>wrote:
>
>> Hi all,
>>
>> I plan to fit a mixed-effects meta-regression model with metafor::rma().
>> The moderator would be categorical (3 subgroups). If I’m not mistaken,
>> rma() estimates a common tau^2 across subgroups.
>>
>> Is it possible to estimate a separate tau for each subgroup?
>>
>> I believe it is possible in the {meta} package through the tau.common
>> argument (https://cran.r-project.org/web/packages/meta/meta.pdf).
>>
>> Thanks,
>>
>> Arthur M. Albuquerque
>>
>> Medical student
>> Universidade Federal do Rio de Janeiro, Brazil
```