Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(metafor)
- library(metaBMA)
- nsims <- 100
- cover <- matrix(0, nrow = 100, 2)
- colnames(cover) <- c("freq", "bayes")
- tau = 0.1
- for(i in 1:nsims) {
- print(i)
- y <- data.frame(
- # generating data for a population d = 0.5 and a given tau
- effsize = rnorm(6, 0.2, tau),
- SE = runif(6, 0.05, 0.1),
- study = 1:6)
- # fitting a frequentist random-effect meta-analysis model
- fit_freq <- rma(effsize, sei = SE, data = y, method = "PM")
- lower_freq <- confint(fit_freq, level = .95)$random[2, 2]
- upper_freq <- confint(fit_freq, level = 0.95)$random[2, 3]
- #fitting a Bayesian random-effect meta-analysis model
- fit_bayes <- meta_random(
- y$effsize, y$SE, y$study,
- d = "norm", d.par = c(0, 10000),
- tau = "halfcauchy", tau.par = 10000,
- sample = 500, summarize = "jags"
- )
- #
- # lower_bayes <- fit_bayes$estimates[2, 6]
- # upper_bayes <- fit_bayes$estimates[2, 7]
- cover[i,] <- c(ifelse(lower_freq < tau && upper_freq > tau, 1, 0),
- ifelse(fit_bayes$estimates[2,4] < tau && fit_bayes$estimates[2,5] > tau, 1, 0))
- # res[i, ] <- cbind(lower_freq, upper_freq, lower_bayes, upper_bayes)
- }
- colMeans(cover)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement