Last active
July 5, 2017 15:29
-
-
Save wviechtb/5393966c2340ddecd0446d6024a36223 to your computer and use it in GitHub Desktop.
Show that FE model has nominal coverage for conditional inferences.
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 | |
cov.w <- rep(NA, iters) | |
cov.u <- rep(NA, iters) | |
for (j in 1:iters) { | |
### simulate estimates with heterogeneous true effects | |
thetai <- rnorm(k, 0, tau) | |
vi <- runif(k, .001, 1) | |
yi <- rnorm(k, thetai, sqrt(vi)) | |
### estimate weighted mean of thetai values | |
res <- rma(yi, vi, method="FE") | |
### check for coverage of the weighted mean | |
wi <- 1/vi | |
theta.mean <- weighted.mean(thetai, w=wi) | |
cov.w[j] <- (res$ci.lb <= theta.mean) && (res$ci.ub >= theta.mean) | |
### 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) | |
cov.u[j] <- (res$ci.lb <= theta.mean) && (res$ci.ub >= theta.mean) | |
} | |
### print coverage rates | |
print(mean(cov.w)) | |
print(mean(cov.u)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment