[R-meta] estimating tau2 under no effect
Filippo Gambarota
||||ppo@g@mb@rot@ @end|ng |rom gm@||@com
Fri Mar 15 12:39:38 CET 2024
Hi,
Maybe a kind of unusual question but I would like to be able to estimate
the variance of a random-effects model assuming that there is no real
effect (mu_theta = 0).
I did this manually maximising the log-likelihood of the random-effect
model by fixing the average effect to 0 and the estimation is very close to
the tau2 estimated with sign-flip permutations (that simulate the null
hypothesis of no effect). I put the code below.
My question is about, is there any way to do this directly in metafor? I
was deeply reading the source code of rma.uni and rma.mv but I am not able
to find a way to trick the model fixing beta to 0.
```
## SIMULATE A DATASET
k <- 50
n <- rpois(k, 40)
d <- 0.5
tau2 <- 0.1
thetai <- rnorm(k, 0, sqrt(tau2))
yi <- vi <- rep(NA, k)
for(i in 1:k){
x0 <- rnorm(n[i], 0, 1)
x1 <- rnorm(n[i], d + thetai[i], 1)
yi[i] <- mean(x1) - mean(x0)
vi[i] <- var(x0)/n[i] + var(x1)/n[i]
}
dat <- data.frame(
id = 1:k,
yi,
vi
)
# random-effect model
fit <- rma(yi, vi, data = dat)
# sign-flip permutations
nperm <- 1000
tau2p <- rep(NA, nperm)
tau2p[1] <- fit$tau2
for(i in 2:nperm){
s <- sample(c(-1, 1), k, replace = TRUE)
yip <- dat$yi * s
fitp <- rma(yip, vi, data = dat)
tau2p[i] <- fitp$tau2
}
# restricted maximum likelihood equation
meta_REML <- function(x, yi, vi){
theta <- x[1]
tau2 <- x[2]
-0.5 * sum(log(tau2 + vi)) - 0.5 * log(sum(1/(tau2 + vi))) - 0.5 *
sum((yi - theta)^2 / (tau2 + vi))
}
# very crude approach, just to see
tau2i <- seq(0, 1, 0.001)
ll <- sapply(tau2i, function(t) meta_REML(c(0, t), dat$yi, dat$vi))
# should be similar, tau2 under H0
tau2i[which.max(ll)]
median(tau2p)
```
Thank you!
--
*Filippo Gambarota, PhD*
Postdoctoral Researcher - University of Padova
Department of Developmental and Social Psychology
Website: filippogambarota.xyz
Research Groups: Colab <http://colab.psy.unipd.it/> Psicostat
<https://psicostat.dpss.psy.unipd.it/>
[[alternative HTML version deleted]]
More information about the R-sig-meta-analysis
mailing list