How to do a meta-analysis in R

Short answer

Put one row per study in a data frame with the numbers needed for your effect measure, then pool the studies with the meta package (metabin, metacont or metagen) or with metafor (escalc and rma). Choose the effect measure and model in advance, report heterogeneity (tau², I² and a prediction interval), and draw a forest plot. Explore small-study effects with a funnel plot only when you have enough studies.

Step by step

  1. 1

    Prepare the data

    Create a data frame with one row per study (or per comparison) and the columns your effect measure needs: events and totals per arm for binary outcomes, or means, standard deviations and sample sizes per arm for continuous outcomes. If studies report an effect estimate and its confidence interval instead, derive the log effect and its standard error.

  2. 2

    Choose the effect measure and the model

    For binary outcomes, a risk ratio or odds ratio; for continuous outcomes, a mean difference, or a standardized mean difference when scales differ. Decide between a common-effect and a random-effects model in your protocol; when studies differ clinically or methodologically, a random-effects model is usually more appropriate.

  3. 3

    Pool the studies with meta

    The meta package wraps the standard methods in a few functions: metabin for binary data, metacont for continuous data and metagen for precomputed effects. Set the heterogeneity estimator explicitly so your results do not change if package defaults change.

    library(meta)
    m <- metabin(event.e = events_trt, n.e = n_trt,
                 event.c = events_ctl, n.c = n_ctl,
                 studlab = study, data = dat, sm = "RR",
                 common = FALSE, random = TRUE,
                 method.tau = "REML")
    summary(m)
    forest(m)
  4. 4

    Or use metafor for more control

    metafor separates computing the effect sizes (escalc) from fitting the model (rma), which makes meta-regression and more complex models straightforward.

    library(metafor)
    es <- escalc(measure = "RR", ai = events_trt, n1i = n_trt,
                 ci = events_ctl, n2i = n_ctl, data = dat)
    res <- rma(yi, vi, data = es, method = "REML")
    summary(res)
    forest(res, transf = exp)
  5. 5

    Read heterogeneity

    Report tau² (the between-study variance), I² (the proportion of variability due to heterogeneity rather than chance) and, for random-effects models, a prediction interval. I² depends on study size and should not be read alone; the Cochrane Handbook gives only rough guides to its interpretation. Explore heterogeneity with pre-specified subgroup analyses or meta-regression rather than by dropping studies.

  6. 6

    Check small-study effects and sensitivity

    Funnel plots and tests such as Egger's are generally recommended only when there are at least 10 studies. Run sensitivity analyses planned in your protocol, for example excluding studies at high risk of bias, and report them.

How Prolytiq does this step

Prolytiq's statistics step generates R scripts from your extraction tables using the meta package, including the pooled analysis, forest plot and funnel plot, with a plain-language explanation of each part. The script is plain R: you can read every line, run it in your own R installation and adapt it.

See the workflow →

Frequently asked questions

Should I use meta or metafor?

Both are well-established. meta is convenient for standard pairwise meta-analyses and publication-ready forest plots; metafor gives more control over models, meta-regression and multilevel structures. Many analysts use both.

How many studies do I need for a meta-analysis?

Two studies can technically be pooled, but with very few studies the between-study variance is estimated poorly and random-effects results should be interpreted with caution. Whether pooling is sensible at all depends on how similar the studies are.

Is a high I² a reason not to pool?

Not automatically. Consider why the studies differ, whether the direction of effect is consistent, and whether a pooled estimate is meaningful. Report heterogeneity and explore it with pre-specified analyses.

Methodological sources

  • Cochrane Handbook for Systematic Reviews of Interventions, chapter 10: Analysing data and undertaking meta-analyses
  • Balduzzi S, Rücker G, Schwarzer G. How to perform a meta-analysis with R: a practical tutorial. Evidence-Based Mental Health, 2019
  • Viechtbauer W. Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 2010

Run your next systematic review in Prolytiq

From research question to publishable chart, with every decision logged and exportable for peer review.

Newsletter

Neurosurgery evidence, once a month

The most relevant new randomized controlled trials and primary studies in neurosurgery, explained in plain language.

We use cookies to improve your experience

Essential cookies (login, session, security) are required. Analytics and marketing depend on your consent. Learn more.

Customize