Advertisement
Guest User

Untitled

a guest
Sep 11th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.20 KB | None | 0 0
  1. library(metafor)
  2. library(metaBMA)
  3.  
  4. nsims <- 100
  5. cover <- matrix(0, nrow = 100, 2)
  6. colnames(cover) <- c("freq", "bayes")
  7. tau = 0.1
  8.  
  9. for(i in 1:nsims) {
  10.   print(i)
  11.   y <- data.frame(
  12.     # generating data for a population d = 0.5 and a given tau
  13.     effsize = rnorm(6, 0.2, tau),
  14.     SE = runif(6, 0.05, 0.1),
  15.     study = 1:6)
  16.  
  17.   # fitting a frequentist random-effect meta-analysis model
  18.   fit_freq <- rma(effsize, sei = SE, data = y, method = "PM")
  19.  
  20.   lower_freq <- confint(fit_freq, level = .95)$random[2, 2]
  21.   upper_freq <- confint(fit_freq, level = 0.95)$random[2, 3]
  22.  
  23.   #fitting a Bayesian random-effect meta-analysis model
  24.    fit_bayes <- meta_random(
  25.      y$effsize, y$SE, y$study,
  26.      d = "norm", d.par = c(0, 10000),
  27.      tau = "halfcauchy", tau.par = 10000,
  28.      sample = 500, summarize = "jags"
  29.    )
  30.   #
  31.   # lower_bayes <- fit_bayes$estimates[2, 6]
  32.   # upper_bayes <- fit_bayes$estimates[2, 7]
  33.  
  34.    
  35.    
  36.   cover[i,] <- c(ifelse(lower_freq < tau && upper_freq > tau, 1, 0),
  37.                  ifelse(fit_bayes$estimates[2,4] < tau && fit_bayes$estimates[2,5] > tau, 1, 0))
  38.  
  39.   # res[i, ] <- cbind(lower_freq, upper_freq, lower_bayes, upper_bayes)
  40.  
  41. }
  42.  
  43. colMeans(cover)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement