Skip to content

Instantly share code, notes, and snippets.

@wviechtb
Created July 5, 2017 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wviechtb/b1798d5e2e2344eb64a46bad9d59266a to your computer and use it in GitHub Desktop.
Save wviechtb/b1798d5e2e2344eb64a46bad9d59266a to your computer and use it in GitHub Desktop.
Show that FE model has nominal coverage for conditional inferences (fixed theta scenario).
rm(list=ls())
library(metafor)
iters <- 1000
### number of studies/effects
k <- 10
### SD of the true effects
tau <- 0.2
### generate heterogeneous true effects whose average is 0
thetai <- rnorm(k, 0, tau)
thetai <- thetai - mean(thetai)
cov.u <- rep(NA, iters)
for (j in 1:iters) {
### simulate estimates with heterogeneous true effects
vi <- runif(k, .001, 1)
yi <- rnorm(k, thetai, sqrt(vi))
### estimate unweighted mean of thetai values
res <- rma(yi, vi, method="FE", weighted=FALSE)
### check for coverage of the unweighted mean
theta.mean <- mean(thetai) # 0 by construction
cov.u[j] <- (res$ci.lb <= theta.mean) && (res$ci.ub >= theta.mean)
}
### print coverage rate
print(mean(cov.u))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment