Introduction to Meta‐Analysis in R using {meta} - erynmcfarlane/StatsGenLabProtocols GitHub Wiki

Welcome to my little meta-analysis crash course! For theory and learning more about meta-analyses and how they work, why we use them, more about using {meta} etc. this guide is fantastic: https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/

install and load packages

install.packages("meta")
install.packages("ggplot2")

library(meta)
library(ggplot2)

preparing the data

let's create a sample dataframe with three columns: source, effect size (OR), and standard error (SE)

source <- c("study 1", "study 2", "study 3", "study 4", "study 5", "study 6", "study 7", "study 8")

OR <- c(0.583, -3.040, 1.542, 2.172, -2.265, 1.582, -1.112, -0.628)

SE <- c(0.256, 0.992, 0.144, 0.649, 0.157, 0.249, 0.496, 0.315)

data <- data.frame(source, OR, SE)

building the meta-analysis model

we can tune the model parameters according to your specific dataset (here i used a paul-mandel estimator for binary effect size data and a knapp-hartung adjustment for the low number of studies)

meta <- metagen(TE = OR,
                     seTE = SE,
                     studlab = source,
                     data = data,
                     sm = "OR",
                     fixed = FALSE,
                     random = TRUE,
                     method.tau = "PM",
                     hakn = TRUE,
                     prediction = TRUE)

summary(meta)

after looking at the summary, we can see that the between study heterogeneity is high meaning we would want to stick to using the random effects model

creating a forest plot

similarly, we can tune the parameters like any other graph to make it look nicer and display the information we want to display

forest(meta, 
       sortvar = TE,
       prediction = TRUE, 
       print.tau2 = FALSE,
       leftlabs = c("Study", "OR", "SE")

building a meta-regression model

what if we wanted to control for a continious covariate in our meta-anlaysis? we can update our sample dataframe to test this out

cont_covar <- c(16, 9, 19, 11, 10, 1, 3, 7)

data <- data.frame(source, OR, SE, cont_covar)

now we plug our meta-analysis model into the metareg function to conduct a meta-regression

metareg <- metareg(meta, ~ cont_covar, 
                   method.tau = "PM",
                   hakn = TRUE)

summary(metareg)

creating a bubble plot

we can visualize the meta-regression with a bubble plot using the bubble function in {meta} but it's not very pretty! also, no CI bars make this an unhelpful graph to look at

bubble(metareg,
       col.ref = "red") 

an alternative is to use ggplot to construct a bubble plot with the same data... but first we have to extract the values from the original meta-analysis and create a dataframe that we can use

metareg_df <- data.frame(meta)

metareg_df <- cbind(metareg_df, cont_covar = data$cont_covar)

now we can plug this new dataframe into our familiar ggplot function and play around with the graph to make it look nice

ggplot(metareg_df, aes(x = cont_covar, y = TE, size = w.random, colour = studlab, fill = studlab)) +
  scale_x_continuous(limits = c(0, 20), breaks = c(0, 5, 10, 15, 20)) +
  scale_y_continuous(limits = c(-5, 4), breaks = seq(-5, 4, 2)) +
  geom_errorbar(aes(x = cont_covar, y = TE, ymin = lower, ymax = upper), size = 1) +
  geom_point(shape = 21, stroke = 1.5, alpha = 0.5) +
  scale_size(range = c(5, 13)) +
  geom_abline(intercept = coef(metareg)[1], slope = coef(metareg)[2]) +
  geom_hline(yintercept = 0, colour = "red") +
  labs(x = "\nContinuous Covariate", y = "Log Odds Ratio\n") +
  guides(size = FALSE, fill = FALSE) +
  labs(colour = "Source") +
  theme_light()

note: unfortunately i have not figured out a way to backtransform the y-axis from log odds ratio to odds ratio without messing up the scale, any solutions are very welcome!

aaaand now we're done! :)