Skip to content

Instantly share code, notes, and snippets.

@JimGrange
Created May 10, 2018 21:14
Show Gist options
  • Save JimGrange/c37273af61fc7c0216aeb2174922da77 to your computer and use it in GitHub Desktop.
Save JimGrange/c37273af61fc7c0216aeb2174922da77 to your computer and use it in GitHub Desktop.
library(metafor)
library(dplyr)
# sample size per study
n <- 10
# population effect size
true_d <- 0.2
# generate studies
data <- data.frame(
study = rep(c("a", "b", "c", "d", "e", "f", "g"),
each = n),
dv = rnorm(n = n * 7, mean = true_d)
)
# calculate summary statstics
data <- data %>%
group_by(study) %>%
summarise(mean = mean(dv), se = sd(dv) / sqrt(n))
# conduct and plot the meta analysis
ma_out <- rma(data = data, yi = mean, sei = se, slab = data$study)
forest(ma_out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment