# [R-meta] simulating three-level meta-analysis

Filippo Gambarota ||||ppo@g@mb@rot@ @end|ng |rom gm@||@com
Wed Jun 15 13:44:15 CEST 2022

Hello!
I'm trying to simulate a three-level meta-analysis model but I'm stuck
on understanding how to generate sampling variances that will be
associated with a certain value of tau2 (level 2) and tau3 (level 3).
My approach so far is setting values for population parameters and
generating sampling variances for the effect ij:

```
library(metafor)

b0 <- 0.3 # effect
ni <- 100 # number of papers
nj <- 5 # number of effects within each paper

taui <- 0.3 # level 3 tau
tauj <- 0.1 # level 2 tau
icc <- taui^2 / sum(taui^2 + tauj^2) # real ICC

# i-level data
dati <- data.frame(paper = 1:ni,
b0_i = rnorm(ni, 0, taui))

# j-level data
datj <- data.frame(paper = rep(1:ni, nj),
study = 1:sum(nj),
b0_j = rnorm(sum(nj), 0, tauj))

dat <- merge(dati, datj, by = "paper") # combine
dat\$vi <- runif(nrow(dat), 0, 0.3) # sampling variances at level 1
dat\$yi <- b0 + dat\$b0_i + dat\$b0_j + rnorm(nrow(dat), 0, dat\$vi)

fit <- rma.mv(yi, vi, random = ~study|paper, data = dat)
```
However, I'm sure that I'm doing wrong because taus are estimated
using vi and the vis are not sampled with specific criteria.
Does someone have some hints? Or in general suggestions about to setup
a simulation like this?
Thanks!

--
Filippo Gambarota
PhD Student - University of Padova
Department of Developmental and Social Psychology
Website: filippogambarota
Research Group: Colab   Psicostat