Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 039
Research workflow/4 steps

Mendelian randomization: genes as instruments for a causal effect (TwoSampleMR)

Source TwoSampleMR — MRC IEU (Hemani, Davey Smith et al.)
01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 4 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 4
01
Data prep

Harmonise SNP–exposure & SNP–outcome effects

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Each SNP is a candidate instrument. Align effect alleles across the two GWAS so the signs are comparable.

Formula
Z_j\to X,\qquad Z_j\perp\!\!\!\perp U,\qquad Z_j\to Y\ \text{only via}\ X
Reads fromNot specified Feeds intoNot specified
Key code
dat <- harmonise_data(exp, out)

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.

Questions to explore
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

GWAS summary statistics: for each SNP, its effect on the exposure and on the outcome (with standard errors), harmonised to a common effect allele.

Show data format & exampleHide example

Format — per-SNP effects on exposure and outcome, harmonised.

library(TwoSampleMR)
exp <- extract_instruments('ieu-a-2')           # BMI instruments
out <- extract_outcome_data(exp$SNP, 'ieu-a-7')  # coronary heart disease
dat <- harmonise_data(exp, out)
res <- mr(dat)
03
Read the evidence

Results & interpretation

2 figures Workflow discussion 2
01FigureThe MR scatter: each point is a genetic instrument (SNP effect on outcome vs. on exposure); the slope of each method line is the estimated causal effect of the exposure.
02FigureSingle-SNP forest plot: each instrument's Wald-ratio estimate and the pooled effect at the bottom — heterogeneity flags pleiotropy.

Figures reproduced from TwoSampleMR — MRC IEU (Hemani, Davey Smith et al.) — unofficial community showcase; all credit to the original authors.

Context & interpretation

⚠️ Unofficial community showcase of twosamplemr. Not affiliated with the authors; all credit to them.

Use genetic variants as instruments to estimate the causal effect of an exposure on an outcome from GWAS summary data — with IVW plus pleiotropy-robust MR-Egger and weighted-median checks.

Peer notes

Discuss the workflow (2)

  • 2

    Genes as instruments is the cleanest natural experiment we get — but the MR-Egger intercept and weighted-median checks are non-negotiable. Pleiotropy is everywhere.

  • 0

    The scatter with all five estimator slopes on one plot is the right way to show robustness at a glance. Saved.

    1

    Agreed — if IVW and Egger disagree wildly, that's the figure that makes the pleiotropy story obvious to a reviewer.

IN THE MARGINS

Peer discussion