Code
install.packages(c("dplyr", "tidyr", "ggplot2", "knitr", "kableExtra",
"rentrez", "xml2", "europepmc", "irr", "PRISMA2020",
"survival", "epiR", "metafor", "meta", "robvis", "medicaldata"))Systematic reviews and meta-analysis with R and Bayesian reasoning
This book grew out of EPIB 629, Knowledge Synthesis, a graduate course in systematic reviews and meta-analysis at McGill University. It is written for readers who want to do more than follow a checklist: to understand why each step of a review exists, to recognise when a published review has gone wrong, and to carry out every analysis themselves, reproducibly, in R.
It also reflects how I learn. I find I only really understand a method once I can code it. AI tools can now write much of that code, but they have not reduced the need to read it critically: to know what each line assumes and whether its output makes sense. Understanding code also opens the door to simulation: generating data in which the truth is known, to see how a method behaves or to test whether a published analysis could have produced the result it reports. Simulation recurs throughout the book as one more tool for critical reading and analysis. That is why the code in this book is shown in full and explained rather than hidden.
The second habit is to place every result in context. A new study should update what was already known, not replace it, which leads directly to Bayesian reasoning. My interest in it dates from my PhD, one of whose papers re-analysed the GUSTO trial in this way (1). Bayesian ideas appear from Chapter 1 onwards and are developed fully in Chapters 13 and 22.
The book assumes roughly one introductory course in epidemiology and one in statistics. No previous experience with systematic reviews, meta-analysis or Bayesian methods is needed; where these ideas first appear, they are built up from the beginning.
Clinicians, epidemiologists, guideline developers and graduate students are the intended readers. The examples come mostly from cardiovascular medicine and clinical trials, but the methods apply across health research.
Each chapter corresponds to one lecture of the course and follows the same pattern:
The planned chapters are:
| Part | Chapters |
|---|---|
| Foundations | 1 Introduction · 2 Finding the evidence · 3 From question to data · 4 Visualising evidence |
| Appraisal | 5 Risk of bias and GRADE · 6 Rating certainty with GRADE · 7 Reporting and appraising systematic reviews |
| Meta-analysis | 8 Effect measures · 9 Meta-analysis models · 10 Heterogeneity and robustness · 11 P values · 12 Bias and a bridge to Bayes · 13 Bayesian meta-analysis |
| Threats and extensions | 14 Missing data · 15 Publication bias · 16 Individual participant data · 17–18 Network meta-analysis · 19 Observational studies · 20 Diagnostic accuracy |
| From evidence to decisions | 21 Cochrane reviews and single trials · 22 Health technology assessment · 23 Correcting the literature · 24 Agentic meta-analysis |
Code is not an appendix to this book; it is how the ideas are made concrete. Every analysis is shown in full, at the point in the text where it is discussed, so that you can read the argument and the code together. Each code block is preceded by a sentence or two saying what it does and followed by an interpretation of the output, so readers who prefer not to read the code can still follow the argument.
If you prefer to read only the text, choose Hide All Code from the </> Code menu at the top right of any chapter; each code block can also be collapsed or expanded individually by clicking its Code label. The interpretation that follows each block is written to stand on its own.
You do not need to copy code from the page. For every chapter, all of its R code is also available as a single script, code/<chapter>.R, which runs from top to bottom in RStudio. Examples that query online databases also come with a saved copy of the results in data/, so every chapter can be rebuilt without an internet connection and gives the same numbers each time.
Four kinds of boxes appear throughout:
Background, definitions and asides.
The messages to remember.
Common misunderstandings and practices to question.
Errors with serious consequences for a review’s conclusions.
All analyses use R and, for writing, Quarto; RStudio is a convenient way to use both. Each chapter lists the packages it needs at its start. The main ones are:
| Purpose | Packages |
|---|---|
| Data handling and graphics | dplyr, tidyr, ggplot2 |
| Searching the literature | rentrez, xml2, europepmc |
| Screening and reporting | irr, PRISMA2020 |
| Frequentist meta-analysis | meta, metafor, netmeta |
| Bayesian meta-analysis | brms (with Stan), bayesmeta, RoBMA |
| Risk of bias displays | robvis |
| Effect sizes and survival analysis | epiR, survival |
To install the packages used in the first chapters:
install.packages(c("dplyr", "tidyr", "ggplot2", "knitr", "kableExtra",
"rentrez", "xml2", "europepmc", "irr", "PRISMA2020",
"survival", "epiR", "metafor", "meta", "robvis", "medicaldata"))I have had the opportunity to learn from many esteemed colleagues as well as students and at the risk of offending anyone by leaving them out, I will simply say a big thank you to all. Importantly this work would not have been possible without the supportive and harmonious environment I share with Lynda.
CC BY-NC-ND 4.0 for the text, with code under the MIT licence.