Created
July 5, 2017 18:41
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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