About this page
How-to guide- What this page solves
- You want to know whether an exposure, such as LDL cholesterol, has a causal effect on a disease, such as coronary heart disease. Observational studies are easily confounded, so you want to use two public GWAS summary statistics for Mendelian randomisation.
- Who it is for
- Medical graduate students writing a two-sample MR paper with TwoSampleMR. They know basic GWAS concepts and can run R code.
- What you will have
- You will have an aligned analysis dataset, an instrument table with F and R², a results table for IVW and the sensitivity analyses, and the STROBE-MR reporting points for the methods section.
- Covers
- Completing a two-sample MR with two public GWAS summary statistics
- Instrument selection, allele harmonisation, main analysis and sensitivity analyses
- A local workflow without an OpenGWAS token, and how to set up a token
- Reporting results and common errors (see the troubleshooting section)
- Does not cover
- Single-sample MR using individual-level data
- Genotyping and quality control of the GWAS itself
- Multivariable MR
Main steps
Step 1 · Data
Why this stepTwo-sample MR needs two summary statistics: the exposure (LDL-C here) and the outcome (coronary heart disease here). Each must include the SNP, the effect allele, β, its standard error, the P value and the sample size.
In this example, the GLGC 2013 LDL-C data are the exposure and GWAS Catalog GCST003116 (CARDIoGRAMplusC4D 2015) is the outcome. The two come from different studies, but participants may partly overlap; this page did not verify the overlap.
Text files are read with fread. Column names differ between sources, so rename them to a common set with setnames first.
Confirm the effect allele for each file. The GLGC effect allele column is A1 and FinnGen uses alt; the columns for each source are listed in the reference section.
OpenGWAS online data, GWAS Catalog harmonised files, IEU VCF and Pan-UKB each need a different read step, and the code covers each one.
library(TwoSampleMR); library(data.table) # fread on .gz files also needs R.utils
## A. Exposure: text summary statistics from the authors' site or GWAS Catalog (GLGC 2013 LDL-C)
ldl <- fread("jointGwasMc_LDL.txt.gz")
setnames(ldl, c("P-value", "Freq.A1.1000G.EUR"), c("pval", "eaf"))
class(ldl$pval) # measured here: "character", because the file contains values such as 1.24e-652
ldl[, pval := as.numeric(pval)] # without conversion, pval < 5e-8 is a string comparison
ldl[, `:=`(A1 = toupper(A1), A2 = toupper(A2))] # GLGC alleles are lower case; A1 is the effect allele
exp_dat <- format_data(as.data.frame(ldl[pval < 5e-8]), type = "exposure",
snp_col = "rsid", beta_col = "beta", se_col = "se", eaf_col = "eaf",
effect_allele_col = "A1", other_allele_col = "A2", pval_col = "pval", samplesize_col = "N")
## B. Outcome: GWAS Catalog harmonised file (*.h.tsv.gz, GRCh38, hm_ columns share one orientation)
# Keep only instrument rows with awk first: about 80 s for the 370 MB file, so R never reads 8.6 million rows
# gzip -dc GCST003116.h.tsv.gz | awk -F'\t' 'NR==FNR{a[$1];next} FNR==1 || ($2 in a)' snps.txt - > cad_subset.tsv
cad <- fread("cad_subset.tsv")
out_dat <- format_data(as.data.frame(cad), type = "outcome", snps = exp_dat$SNP,
snp_col = "hm_rsid", beta_col = "hm_beta", se_col = "standard_error",
eaf_col = "hm_effect_allele_frequency", effect_allele_col = "hm_effect_allele",
other_allele_col = "hm_other_allele", pval_col = "p_value", chr_col = "hm_chrom", pos_col = "hm_pos")
## C. IEU OpenGWAS VCF: FORMAT is ES:SE:LP:AF:SS:ID, LP is -log10(P), the effect allele is ALT
# bcftools query -f '%ID\t%CHROM\t%POS\t%ALT\t%REF\t[%ES]\t[%SE]\t[%LP]\t[%AF]\t[%SS]\n' ieu-a-300.vcf.gz > ieu-a-300.tsv
v <- fread("ieu-a-300.tsv", col.names = c("SNP","chr","pos","effect_allele","other_allele","beta","se","lp","eaf","samplesize"))
exp_vcf <- format_data(as.data.frame(v), type = "exposure", pval_col = "lp", log_pval = TRUE)
## D. Pan-UKB: the P column is neglog10_pval_EUR, so also use log_pval = TRUE; alt is the effect allele, GRCh37Step 2 · Instruments
Why this stepInstruments are SNPs associated with the exposure. First keep SNPs at genome-wide significance, P < 5e-8. These SNPs may be correlated with one another, so clumping then keeps an approximately independent set.
In this example, P < 5e-8 gives 3,078 SNPs, or 3,060 after removing duplicates. Set the P threshold and clump parameters before seeing the outcome results, and state them in the methods.
Clumping uses local plink with the 1000 Genomes European (EUR) reference panel, with r² = 0.001 and a 10,000 kb window. In this example 79 SNPs remain after clumping.
SNPs absent from the reference panel are dropped. In this example 132 of the 3,060 significant SNPs are missing, and the smallest of them has P = 4.3e-127; state this in the methods.
Online clumping needs a token. For choosing between local and online workflows, see the choice on OpenGWAS tokens. If there are too few instruments, see the choice on relaxing the P threshold.
# Reference panel: http://fileserve.mrcieu.ac.uk/ld/1kg.v3.tgz (1.57 GB, EUR/EAS/AFR/AMR/SAS)
# Extract only the population you need: tar -xzf 1kg.v3.tgz EUR.bed EUR.bim EUR.fam
# plink 1.9 from conda (bioconda::plink) or genetics.binaRies::get_plink_binary()
library(ieugwasr)
# First count significant SNPs missing from the panel: ld_clump drops them silently
bim <- data.table::fread("ref/EUR.bim", select = 2)
miss <- exp_dat[!exp_dat$SNP %in% bim$V2, ]
nrow(miss); min(miss$pval.exposure) # measured here: 132 SNPs, smallest P 4.3e-127
clumped <- ld_clump(
dplyr::tibble(rsid = exp_dat$SNP, pval = exp_dat$pval.exposure, id = exp_dat$id.exposure),
clump_kb = 10000, clump_r2 = 0.001, clump_p = 1,
bfile = "ref/EUR", # file prefix, without .bed
plink_bin = Sys.which("plink"))
exp_dat <- exp_dat[exp_dat$SNP %in% clumped$rsid, ]Step 3 · Instrument strength
Why this stepThe F statistic measures how well an instrument explains the exposure. A small F means a weak instrument, and weak instruments bias estimates toward zero. F is computed from each SNP's effect and standard error.
Per-SNP F is approximated as (β/SE)². In this example the minimum is 27.8 and the median is 58.4. An F above 10 is a common rule of thumb, but it does not guarantee that bias is absent.
Total R² is the sum of the variance each SNP explains in the exposure; here it is 0.085, and the overall F is 201. At P < 5e-8, each SNP's F is automatically above 29.7; see the reference section.
A wrong R² formula gives very different values; see the troubleshooting section.
# Per-SNP F statistic (approximation)
exp_dat$F <- (exp_dat$beta.exposure / exp_dat$se.exposure)^2
# Variance explained R2 (form that includes SE and N; for a continuous trait with beta in SD units)
b <- exp_dat$beta.exposure; s <- exp_dat$se.exposure
f <- exp_dat$eaf.exposure; N <- exp_dat$samplesize.exposure
exp_dat$R2 <- 2*b^2*f*(1-f) / (2*b^2*f*(1-f) + 2*s^2*N*f*(1-f))
# Overall F: k SNPs, total R2
k <- nrow(exp_dat); R2 <- sum(exp_dat$R2, na.rm = TRUE)
F_all <- R2 * (median(N) - k - 1) / (k * (1 - R2))
# Measured here (79 SNPs): per-SNP F min 27.8, median 58.4; total R2 0.085; overall F 201Step 4 · Harmonisation
Why this stepHarmonisation makes the β values for exposure and outcome refer to the same effect allele. The two datasets may use different effect alleles; without alignment the signs flip and the causal direction is wrong. In this example, 36 of the 79 SNPs need their alleles swapped.
Use harmonise_data with the default action = 2. It swaps the SNPs that need swapping and flags palindromic SNPs whose direction cannot be inferred.
Palindromic SNPs have alleles A/T or C/G. In this example 2 are removed and 77 are kept. The three action options are compared in the choice on palindromic SNPs and the action parameter.
Removed SNPs remain in the data frame, marked mr_keep = FALSE. Filter on this column before analysis.
dat <- harmonise_data(exp_dat, out_dat, action = 2)
attr(dat, "log") # counts of switched and removed SNPs, for the supplement
dat <- dat[dat$mr_keep, ] # removed rows stay in the data frame; filter before exporting tablesStep 5 · Main analysis
Why this stepInverse-variance weighted (IVW) is the main method in two-sample MR. It averages the per-SNP effect ratios with inverse-variance weights, and assumes all instruments are valid.
mr() computes IVW, fixed-effect IVW, MR-Egger, the weighted median and the weighted mode together. The mr_ivw default in TwoSampleMR is a multiplicative random-effects model, which widens the confidence interval when heterogeneity is large. The main result here is IVW.
generate_odds_ratios converts β values to odds ratios and 95% confidence intervals. In this example, each 1 SD higher LDL-C is associated with an OR of 1.51 for coronary heart disease.
The same block also computes Cochran's Q heterogeneity test, the MR-Egger intercept and leave-one-out results. Their meaning is explained in the section on method assumptions.
res <- mr(dat, method_list = c("mr_ivw", "mr_ivw_fe", "mr_egger_regression",
"mr_weighted_median", "mr_weighted_mode"))
generate_odds_ratios(res)
mr_heterogeneity(dat) # Cochran's Q
mr_pleiotropy_test(dat) # MR-Egger intercept
Isq(dat$beta.exposure, dat$se.exposure) # I2GX; below 0.9 MR-Egger suffers regression dilution
loo <- mr_leaveoneout(dat); ss <- mr_singlesnp(dat)Step 6 · Sensitivity
Why this stepAn instrument may affect the outcome through a route other than the exposure; this is pleiotropy. Pleiotropy can bias IVW. Sensitivity analyses use methods with different pleiotropy assumptions to check whether the IVW conclusion is stable.
The MR-Egger intercept tests directional pleiotropy. The weighted median gives a consistent estimate when more than half the weight comes from valid instruments. MR-PRESSO finds outlier SNPs and gives a corrected estimate.
The Steiger directionality test checks whether SNPs explain more variance in the exposure than in the outcome. Here the SNPs explain R² = 0.083 of the exposure and 0.0058 of the outcome, so the direction is correct.
MR-PRESSO needs NbDistribution of at least 20 times the SNP count, or the outlier test is unstable; see the troubleshooting section.
Plots are made with mr_scatter_plot, mr_forest_plot, mr_leaveoneout_plot and mr_funnel_plot.
# Steiger: for a binary outcome compute r.outcome first, otherwise it is approximated as continuous
dat$r.outcome <- get_r_from_lor(dat$beta.outcome, dat$eaf.outcome,
ncase = 60801, ncontrol = 123504, prevalence = 0.05)
dat$r.exposure <- get_r_from_bsen(dat$beta.exposure, dat$se.exposure, dat$samplesize.exposure)
directionality_test(dat)
# MR-PRESSO: NbDistribution at least 20 times the number of SNPs, otherwise the outlier test lacks precision
library(MRPRESSO)
nb <- max(1000, ceiling(nrow(dat) * 20 / 1000) * 1000)
pr <- mr_presso(BetaOutcome = "beta.outcome", BetaExposure = "beta.exposure",
SdOutcome = "se.outcome", SdExposure = "se.exposure", data = dat,
OUTLIERtest = TRUE, DISTORTIONtest = TRUE, NbDistribution = nb, seed = 2026)
# Plots
mr_scatter_plot(res, dat); mr_forest_plot(ss); mr_leaveoneout_plot(loo); mr_funnel_plot(ss)Step 7 · Report
Why this stepThe results table should list the main and sensitivity estimates together. The methods section should state the data, the instruments and the assumptions so readers can reproduce the analysis. STROBE-MR is the reporting checklist for MR studies, with 20 items.
The STROBE-MR items reviewers check most are: item 5, the three assumptions; item 7, the methods for assessing them; item 9, software, package versions and settings, and whether the study was pre-registered; item 10d, the similarity of exposure and outcome samples and the number of overlapping participants; item 11, results on an interpretable scale; and item 13, sensitivity and directionality tests.
The 2023 Burgess et al. guideline suggests a positive-control outcome: choose an outcome whose causal link is established and check whether the instruments reproduce it. LDL-C and coronary heart disease are a well-accepted positive control, so they can check the workflow.
For arguing the three assumptions, see the section on the three assumptions.
| Method | SNPs | β (SE) | OR (95% CI) | P |
|---|---|---|---|---|
| IVW (multiplicative random effects) | 77 | 0.412(0.051) | 1.51(1.37–1.67) | 6.7×10⁻¹⁶ |
| IVW (fixed effect) | 77 | 0.412(0.023) | 1.51(1.44–1.58) | 7.6×10⁻⁷⁰ |
| MR-Egger | 77 | 0.503(0.078) | 1.65(1.42–1.93) | 1.0×10⁻⁸ |
| Weighted median | 77 | 0.396(0.044) | 1.49(1.36–1.62) | 3.1×10⁻¹⁹ |
| Weighted mode | 77 | 0.540(0.079) | 1.72(1.47–2.01) | 2.1×10⁻⁹ |
| MR-PRESSO corrected (8 removed) | 69 | 0.437(0.032) | 1.55(1.45–1.65) | 6.4×10⁻²¹ |
| FinnGen R13 replication (IVW) | 77 | 0.274(0.032) | 1.32(1.24–1.40) | 7.4×10⁻¹⁸ |
Choose by your situation
Choices
Since May 2024, most OpenGWAS API requests need a JWT token that is valid for 14 days. Whether to use one depends on the data source and the scale of the analysis.
From version 0.6.0 (April 2024), TwoSampleMR depends on ieugwasr with the new authentication system, and from 0.6.20 it requires ieugwasr ≥ 1.1.0. Older versions cannot reach OpenGWAS even with a token.
The full offline code is in step 1. The online API is metered by points and rate-limited, while the offline route is unaffected; the point costs are in the reference section.
# 1. Sign in at https://api.opengwas.io/profile and generate a token (valid for 14 days)
# 2. Add it to ~/.Renviron (or .Renviron in the project directory); the variable must be OPENGWAS_JWT
usethis::edit_r_environ()
# Add one line to the opened file: OPENGWAS_JWT=eyJhbGciOi... (no quotes, end with a newline)
# 3. Restart R and check
ieugwasr::get_opengwas_jwt() # a long string means the token was read
ieugwasr::user() # account info means the token works; 401 means expired or mis-copied
# 4. The current argument name is opengwas_jwt; access_token from older tutorials no longer exists
exp <- TwoSampleMR::extract_instruments("ieu-a-300", p1 = 5e-8, r2 = 0.001, kb = 10000)| Situation | What to do |
|---|---|
| Batch analysis, or a paper that must be reproducible | Offline route: download the summary statistics, clump locally, so results do not change when the OpenGWAS database is updated |
| Data from GWAS Catalog, FinnGen, Pan-UKB or the original paper's website | Download and read the files; no token is needed at any step |
| Using the OpenGWAS online API | Set up a token valid for 14 days; the code is below |
Choices
When there are too few instruments at 5e-8, the threshold can be relaxed. Give a reason for doing so and also report the results at the strict threshold.
With fewer than 3 SNPs at 5e-8, MR-Egger and other sensitivity analyses cannot run. In that case, relax the threshold to 5e-6 or 1e-5; exposures with few SNPs, such as gut microbiota, often use 1e-5.
After relaxing, instruments are weaker, the winner's curse is stronger and more pleiotropic SNPs appear. In this example, 5e-6 gives 114 SNPs after clumping; the 36 new SNPs have a minimum F of 20.2.
Report the 5e-8 results alongside. SNPs selected at 5e-6 have F automatically above about 20.8, so F > 10 does not show that relaxing is safe.
Choices
When exposure and outcome come from the same samples, results can be biased. Replicating with a different outcome source tests whether the conclusion is stable.
Exposure and outcome should come from the same population. If they differ, LD structure and allele frequencies differ, and palindromic-SNP inference and proxy SNPs both go wrong. Use the EAS reference panel for East Asian data.
FinnGen files have a tabix index, so you only need to fetch the positions of the instruments rather than the whole file. This example replicates with FinnGen R13 I9_CHD; the results are in the table in step 7.
# FinnGen files are tabix-indexed: fetch only the instrument positions instead of the full 810 MB file
# regions_hg38.tsv has two columns: chromosome (1-23, no "chr") and GRCh38 position,
# e.g. from hm_chrom and hm_pos in the GWAS Catalog harmonised file
tabix -h -R regions_hg38.tsv \
https://storage.googleapis.com/finngen-public-data-r13/summary_stats/finngen_R13_I9_CHD.gz \
> finngen_chd_subset.tsv
# Columns: #chrom pos ref alt rsids nearest_genes pval mlogp beta sebeta af_alt ... (alt is the effect allele)
# Measured here: 77 positions, 4 min 26 s, 79 rows returned (including multi-allelic sites); a .tbi file is left in the working directoryChoices
The action parameter of harmonise_data decides how palindromic SNPs are handled. When an instrument is missing from the outcome, a proxy SNP can stand in for it.
The tolerance in the harmonise_data source is 0.08, which corresponds to the 0.42–0.58 range. Removed SNPs are not deleted from the data frame; they only get mr_keep = FALSE.
Proxy SNPs: extract_outcome_data defaults to proxies = TRUE, rsq = 0.8 and maf_threshold = 0.3, which aligns alleles of proxy SNPs using LD; this step relies on the OpenGWAS API. Offline, find proxies with plink in the reference panel and use the in-phase output to work out the allele correspondence.
# When an instrument is missing from the outcome, find proxies with r2 >= 0.8 in the local panel
plink --bfile ref/EUR --r2 in-phase with-freqs \
--ld-snp rs646776 --ld-window-kb 500 --ld-window 99999 --ld-window-r2 0.8 \
--out proxy_rs646776
# The PHASE column, e.g. CG/TA, means allele C of the target SNP sits on the same haplotype as allele G of the proxy
# When using the proxy's outcome effect, map its effect allele back to the target SNP's allele with this pairing
# Measured here: about 5 s per SNP; 10 proxies for rs646776 (including rs12740374 at r2 = 1)| action | Method | When to use | This example (outcome CARDIoGRAMplusC4D) |
|---|---|---|---|
| 1 | Assumes both datasets are on the forward strand; palindromic SNPs are not inferred | Both datasets have been harmonised to the forward strand, such as GWAS Catalog harmonised files and FinnGen | All 79 kept |
| 2 (default) | Infers the strand of palindromic SNPs from allele frequency; palindromic SNPs with EAF between 0.42 and 0.58 cannot be inferred and are marked mr_keep = FALSE | Most situations | Keeps 77, removes rs2954029 and rs964184; the same instruments were not removed with the FinnGen outcome |
| 3 | Remove all palindromic SNPs | The outcome has no EAF, or the most conservative sensitivity analysis is wanted | Keeps 76 |
Hand it to an agent
You can describe the analysis in one sentence, and the Scientify research agent will run it on a cloud machine.
Example instruction: "Run a two-sample MR with GLGC 2013 LDL-C summary statistics as the exposure and GWAS Catalog GCST003116 coronary heart disease as the outcome. Use P < 5e-8, local 1000G EUR clumping (r² = 0.001, 10,000 kb), compute F and R², harmonise with action = 2, and run IVW, Egger, weighted median, weighted mode, MR-PRESSO, the Q test, leave-one-out and Steiger. Replicate with FinnGen R13 I9_CHD, and output the methods text and results table in STROBE-MR format."
The agent installs TwoSampleMR, MRPRESSO and plink on the cloud machine, downloads the summary statistics and reference panel, and checks the P value column type, effect allele columns and genome build. It then runs filtering, clumping, harmonisation and all analyses, and outputs the results table, scatter plot, forest plot, leave-one-out plot, funnel plot and a draft methods text.
The project keeps scripts, parameters, logs and data files, and tasks keep running after your computer is turned off.
The agent also reviews the results adversarially. It checks the number of SNPs swapped during harmonisation, whether the fixed or random effects choice matches the Q test, and whether outlier SNPs sit in known pleiotropic loci.
You still need to check the populations and sample overlap of the exposure and outcome GWAS, and whether thresholds and methods were fixed before seeing results.
Also check whether the effect scale of a binary exposure was converted correctly, and whether the wording of the conclusion matches the sensitivity analyses.
Concepts and judgment
Explanation
Only relevance can be tested directly. Independence and exclusion can only be partly tested, so the paper must argue them using sensitivity analyses and biological knowledge.
STROBE-MR item 5 requires the three assumptions to be stated explicitly in the methods.
| Assumption | Meaning | Tests possible | How to argue it in the paper |
|---|---|---|---|
| Relevance | Instruments are strongly associated with the exposure | P < 5e-8; per-SNP F and total R²; overall F | Report R² and F; when the threshold is relaxed, report the 5e-8 sensitivity results |
| Independence | Instruments are unrelated to confounders | Cannot be tested directly; check whether both GWAS corrected for population structure with principal components, and whether they come from the same population | State the population and principal-component correction of both GWAS; for socioeconomic exposures, consider within-family MR |
| Exclusion restriction | Instruments affect the outcome only through the exposure | MR-Egger intercept, Cochran Q, MR-PRESSO global and outlier tests; compare weighted median and mode with IVW | Methods with different pleiotropy assumptions agree in direction; results are stable after removing outliers or known pleiotropic loci |
Explanation
When exposure and outcome samples overlap, the direction and size of bias depend on the strength of the instruments.
Without overlap, weak-instrument bias pulls estimates toward zero and does not create false positives. With overlap, the bias points toward the observational association, and its size changes linearly with the overlap proportion (Burgess et al. 2023 guideline).
With F around 30, even complete overlap gives a relative bias of about 1/F, around 3%. A common way to avoid the problem is to take the exposure from a European consortium or UK Biobank and the outcome from FinnGen. If overlap cannot be avoided, report the proportion and correct with methods such as MRlap.
Explanation
Each method makes a different assumption about pleiotropy. IVW is the main analysis; the others check whether its conclusion holds under different assumptions.
The Burgess et al. guideline notes that when several instruments are invalid, outlier-removal methods such as MR-PRESSO have a high false-positive rate. Results after removing outlier SNPs should be a sensitivity analysis, reported alongside the IVW estimate without removal.
| Method | Holds if | Implementation in TwoSampleMR | What to report |
|---|---|---|---|
| IVW (multiplicative random effects) | All SNPs are valid, or pleiotropy averages to zero | mr_ivw: SE is divided by min(1, residual standard error), so it widens when heterogeneity is large and is never narrower than the fixed-effect version | β, OR and 95% CI of the main analysis |
| IVW (fixed effect) | All SNPs are valid and there is no heterogeneity | mr_ivw_fe: SE is divided by the residual standard error | A supplement when the Q test is not significant; confidence intervals are too narrow when heterogeneity is significant |
| MR-Egger | InSIDE: pleiotropy strength is independent of instrument strength | mr_egger_regression; at least 3 SNPs | Slope and intercept; if I²GX < 0.9 there is regression dilution, which needs SIMEX correction or cautious interpretation |
| Weighted median | More than 50% of the weight comes from valid SNPs | mr_weighted_median, 1,000 bootstrap replicates | Whether the estimate agrees in direction with IVW |
| Weighted mode | The group of SNPs with the largest weights is valid | mr_weighted_mode | As above; this method is conservative and its intervals are wide |
| MR-PRESSO | Outlier SNPs are the source of pleiotropy | At least 4 SNPs; NbDistribution must exceed the SNP count; a warning "Outlier test unstable" appears when SNP count / NbDistribution exceeds 0.05 | Global test P, outlier SNPs, corrected estimate and distortion test P |
| Cochran Q | — | mr_heterogeneity gives Q for IVW and Egger | Q, degrees of freedom, P; I² = (Q − df)/Q |
| Leave-one-out | — | mr_leaveoneout | Whether the estimate crosses zero when each SNP is removed in turn; of limited use with many SNPs |
| Steiger directionality test | SNPs explain more variance in the exposure than in the outcome | directionality_test; for a binary outcome, compute r.outcome with get_r_from_lor first | Whether the direction is correct and its P value; steiger_filtering can remove SNPs with the opposite direction one at a time |
Explanation
MR-Egger and the mode-based method have less power than IVW and wider intervals, so one of them alone being non-significant is common. Judge by direction and point estimate first, then by P value.
| Situation | Interpretation | How to report |
|---|---|---|
| IVW significant, other methods same direction but not significant | Usually lack of power. In this example the Egger SE (0.078) is about 1.5 times the IVW SE (0.051) | State that the directions agree and the point estimates are close; keep IVW as the main conclusion |
| Egger intercept P < 0.05 | Directional pleiotropy is present and IVW is biased | Lead with the Egger, weighted median and mode results; find and describe outlier SNPs; downgrade the conclusion to suggestive |
| Q significant, intercept not significant | Heterogeneity is present; pleiotropy may be balanced | Use the multiplicative random-effects IVW (the TwoSampleMR default) and report Q and I² |
| MR-PRESSO correction changes the estimate significantly (distortion test P < 0.05) | Outlier SNPs substantially change the estimate | Report both; describe the known associations of the loci containing the outlier SNPs |
| Methods point in opposite directions | The causal effect cannot be determined | Check allele harmonisation and units; do not draw a causal conclusion |
| Only 1–3 SNPs | Only the Wald ratio or IVW is possible; Egger needs at least 3 SNPs and MR-PRESSO at least 4 | State that sensitivity analyses are limited; consider a relaxed threshold as a supplement or a larger exposure GWAS |
Explanation
When the exposure is binary, or several exposures or outcomes are tested at once, interpretation needs extra care.
Reading the OR for a binary exposure
When the exposure is a disease, an MR estimate is the effect per one-unit increase in the exposure log-odds. Multiplying by ln 2 ≈ 0.693 gives the effect when the exposure odds double (Burgess and Labrecque 2018). Writing "people with the disease have X times the risk of those without" is a misreading.
Multiple testing
When many exposures or outcomes are tested, apply a Bonferroni correction for the number of tests (for example 0.05/20 = 0.0025 for 20 exposures) or report the FDR. Results between 0.05 and the corrected threshold are reported as suggestive.
Reference and appendix
Reference
The table reflects what was accessible on 2026-10-10. In the methods, state the dataset ID or file name, version, population, sample size, genome build and effect allele column for each source.
OpenGWAS point costs and limits may change with service rules; check the account page and API documentation before use.
| Source | Status, October 2026 | Practical notes | Common mistakes |
|---|---|---|---|
| IEU OpenGWAS | Since 2024-05-01 most API requests need a JWT token valid for 14 days. All user tiers get 100,000 points per 10 minutes. New accounts start on Trial and need to upgrade to Standard as the account page indicates. Website VCF downloads are limited to 20 datasets per 24 hours, with links valid for 2 hours. gwas.mrcieu.ac.uk redirects to opengwas.io | For /tophits with precomputed clumping, 1 point per dataset; with re-clumping, 30 points. /ld/clump costs 12 points per call and /gwasinfo/files 50 points per call. For batches of dozens of exposures, estimate the points first. | Repeated 429 responses can get the account and IP blocked for up to a week; an expired token gives 401 |
| FinnGen | R13 was released on 2026-06-02: 500,186 participants, 2,755 endpoints, over 21 million variants; GRCh38; alt is the effect allele | Official access requires a form to obtain download instructions. The manifest (finngen_R13_manifest.tsv) lists case and control counts and https download links for each endpoint. Files are tabix-indexed, so only the needed positions can be fetched remotely | finn-b-* in OpenGWAS is the earlier R5 release; Finnish LD structure differs from other European populations; new large consortium meta-analyses may include FinnGen, so check overlap when used as the outcome |
| UK Biobank (Neale lab round 2) | 361,194 participants, 4,203 phenotypes; Hail linear regression | Binary phenotypes also use linear regression, so β is on the probability scale. Before MR, convert to an approximate log OR: β/[u(1−u)], where u is the case proportion. Variant IDs are chr:pos:ref:alt and need variants.tsv.bgz to map to rsIDs; GRCh37 | When exposure and outcome both come from UKB, samples overlap completely |
| Pan-UKB | Results are given separately for each ancestry group (EUR, CSA, AFR, EAS, AMR, MID); GRCh37 | The P value column is −log10 P (neglog10_pval_EUR); set log_pval = TRUE on reading. Remove variants with low_confidence_EUR TRUE first | Treating neglog10 as a P value makes threshold filtering wrong throughout |
| GWAS Catalog summary statistics | Available for direct download from FTP. Harmonised files are *.h.tsv.gz, GRCh38, with hm_ prefixed columns already on a consistent strand | Prefer hm_rsid, hm_effect_allele and hm_beta from the harmonised file. Raw file column names differ, so read the readme first | Mixing hm_beta with the raw beta column gives inconsistent directions |
Reference
Set the threshold, clump parameters and reference panel before seeing results, and state them in the methods.
Per-SNP F is approximately z², so at P < 5e-8 the F is automatically above 29.7, above 20.8 at P < 5e-6, and above 19.5 at P < 1e-5. After filtering at these thresholds, "all SNPs have F above 10" adds no information. More useful are the total R² and overall F, and comparing weak SNPs when the threshold is relaxed.
| Setting | Common values | Rationale | Risks and measured results in this example |
|---|---|---|---|
| P threshold | 5e-8 | Genome-wide significance standard | Measured for LDL-C: 3,078 SNPs, 79 after clumping |
| Relaxed P threshold | 5e-6 or 1e-5 (1e-5 is common for exposures with few SNPs, such as gut microbiota) | With fewer than 3 SNPs at 5e-8, MR-Egger and other sensitivity analyses are not possible | Instruments are weaker, the winner's curse is stronger and more pleiotropic SNPs appear. Measured here: 5e-6 gives 114 SNPs after clumping, with the 36 new ones having minimum F 20.2. Report the 5e-8 results alongside |
| clump r² | 0.001 | Defaults of TwoSampleMR and ieugwasr, which keep instruments approximately independent | At 0.01 or higher, SNPs remain correlated, so use a correlated IVW with an LD matrix (MendelianRandomization::mr_ivw(correl = TRUE)) |
| Clump window | 10,000 kb | Default | A window that is too small keeps correlated SNPs in long-LD regions |
| Reference panel | 1000 Genomes EUR (503 people, 8,550,156 variants) | Match the population of the exposure GWAS; use EAS for East Asian data | SNPs absent from the panel are dropped. Measured here: 132 of 3,060 significant SNPs missing, 38 of them with P < 1e-20 |
Reference
Run conditions: macOS arm64, 8 cores, 16 GB RAM; R 4.5.3, TwoSampleMR 0.7.12, ieugwasr 1.2.0, MRPRESSO 1.0, MendelianRandomization 0.10.0, meta 8.5.0, PLINK 1.9, htslib 1.24. Exposure: GLGC 2013 LDL-C (2,437,751 SNPs, maximum N about 173,000). Outcome: CARDIoGRAMplusC4D 2015 (GWAS Catalog GCST003116 harmonised file, 60,801 cases and 123,504 controls), replicated with FinnGen R13 I9_CHD (90,714 cases and 409,472 controls). No OpenGWAS token was used at any step.
These results show three things. First, when the Q test is highly significant, the fixed-effect IVW SE is only 46% of the random-effects SE, and the P values differ by 54 orders of magnitude; reporting the fixed-effect model overstates precision.
Second, the outlier SNPs found by MR-PRESSO include known pleiotropic loci such as SH2B3 (rs3184504) and ABO (rs579459). Removing them moves the estimate from 0.412 to 0.437; the distortion test is not significant and the conclusion holds.
Third, the same instruments give OR 1.51 in one outcome source and 1.32 in the other, with a heterogeneity test P = 0.022. FinnGen I9_CHD is a "major coronary heart disease event" endpoint based on registry data, in a Finnish population; both the outcome definition and the population can change the effect size.
# Combine IVW estimates for one exposure from two independent outcome sources (meta 8.5)
library(meta)
m <- metagen(TE = c(0.4123, 0.2741), seTE = c(0.0511, 0.0318),
studlab = c("CARDIoGRAMplusC4D 2015", "FinnGen R13 I9_CHD"),
sm = "OR", common = TRUE, random = TRUE)
forest(m)
# Measured here: common effect OR 1.37 (1.30-1.44); random effects 1.40 (1.22-1.60); Q = 5.28, P = 0.022, I2 = 81%- 01
Filtering and clumping
P < 5e-8 gave 3,078 SNPs, or 3,060 after de-duplication. Local plink clumping (r² = 0.001, 10,000 kb, 1000G EUR) took 3 seconds and kept 79. Reading and clumping took 22 seconds in total, with a peak memory of about 2 GB.
- 02
Instrument strength
Per-SNP F minimum 27.8, median 58.4; total R² 0.085; overall F 201.
- 03
Harmonisation
harmonise_data (action = 2) swapped alleles for 36 SNPs, removed 2 intermediate-frequency palindromic SNPs, and 77 entered the analysis.
- 04
Main analysis and sensitivity
IVW shows that each 1 SD higher LDL-C is associated with an OR of 1.51 for coronary heart disease. The Egger intercept P = 0.13; the Q test is highly significant. MR-PRESSO finds 8 outlier SNPs, and removing them barely changes the estimate. Leave-one-out estimates range from 0.386 to 0.455, with the largest P at 1.4×10⁻¹³. Steiger: R² 0.083 for the exposure and 0.0058 for the outcome, so the direction is correct.
- 05
Replication in an independent outcome
Using tabix to fetch 77 positions from FinnGen R13 remotely took 4 minutes 26 seconds. IVW OR 1.32; the direction agrees and the effect is smaller.
Reference
| Challenge | Analysis to address it | What to write in the paper |
|---|---|---|
| Horizontal pleiotropy | MR-Egger intercept, MR-PRESSO global test, weighted median and mode; check the known associations of loci with outlier SNPs, remove them and rerun | Methods agree in direction; results after removing known pleiotropic loci; if needed, a multivariable MR adjusting for the main pleiotropic pathway |
| Weak instruments | Total R² and overall F; compare with the 5e-8 results when the threshold is relaxed | Report per-SNP F and total R²; explain that weak instruments bias toward zero when samples do not overlap |
| Sample overlap | Check the cohort lists of both GWAS; replicate with a non-overlapping outcome source; MRlap correction | Number or proportion of overlapping participants; replication results from an independent source |
| Population stratification | Whether both GWAS corrected for principal components; whether exposure and outcome come from the same ancestry group | State the number of principal components and the population; for socioeconomic exposures, discuss the possibility of within-family MR |
| Reverse causation | Steiger directionality test; reverse MR | Steiger results and estimates after steiger_filtering |
| Only public data, conclusion seems unoriginal | Positive-control outcome; replication in an independent outcome source; comparison with RCTs or observational studies | Forest plot of replication results; comparison with existing evidence |
Community experience
The points below come from CSDN. Only entries with an error message or the author's measurements, and that agree with official documentation or this page, are included. Some "pitfall" articles are templated; they write the token variable as IUEUGWAS_TOKEN and say action = 2 keeps all SNPs, and both contradict the source code.
401 error and token reset
An author (November 2025) recorded the error "Status code from OpenGWAS API: 401". The fix was to register, write OPENGWAS_JWT into .Renviron, and reset the token on the account page when it expires. This matches the official 14-day validity, and this page reproduced the same error.
Column names and paths for local clumping
An author (April 2024) switched to local plink clumping after online clumping kept timing out. The author notes that the data frame columns must be renamed to rsid and pval, and bfile must be the reference file prefix. This matches the ieugwasr documentation, and it passed on this page.
Same data and code, different P values from the paper
An author (June 2023, over 9,000 views) reproduced an MR paper using the original data and code. The OR and confidence intervals were close, but the P values differed. OpenGWAS datasets and package versions both change, so state package versions and download dates in the paper and keep the data files used. The access_token argument in that code now errors in the current version.
Excel saved as CSV makes every F the same
An author (April 2023) found that every SNP had the same F. After two days of checking, the cause was numeric columns in Excel with General format turning into 0 when saved as CSV. That post's R² formula omitted the square of β; use the formula on this page.
Fields in IEU VCF files
An author (June 2023, 27,000 views) listed the FORMAT fields of IEU VCF: ES is β, SE is the standard error, LP is −log10(P), and AF is the effect allele frequency. These match the GWAS-VCF specification. Exporting with bcftools query is faster than reading the whole file with vcfR and uses less memory.
Troubleshooting by error or symptom
Each entry is titled with the error or symptom you see, with the cause and fix together. Entries are ordered by how often they occur.
Status code from OpenGWAS API: 401 … From 1st May 2024 you must provide a token (JWT)
Cause: The token was not read, or it is more than 14 days old.
Fix: Generate a new token, write it to .Renviron, restart R and check with user(). Setup code is in the choice on OpenGWAS tokens.
After filtering at P < 5e-8 there are far more SNPs than expected, and no error is raised
Cause: The GLGC 2013 LDL-C file has 3 P values below the smallest double (1.24e-652, 6.56e-397, 3.85e-326), so fread reads the whole P column as character. Then pval < 5e-8 compares strings, and 2,435,913 of 2,437,751 rows "pass" the filter. Clumping then gives 1,837 instruments, with no error at any step.
Fix: Check the P column with class() after reading, then convert with as.numeric. The conversion turns those 3 values into 0, and format_data then truncates them at min_pval = 1e-200.
The estimated direction is opposite to the literature or to other analyses
Cause: Wrong effect allele column. GLGC 2013 uses A1; FinnGen, Pan-UKB and Neale use alt; GWAS Catalog harmonised files use hm_effect_allele; IEU VCF uses ALT. Treating ref as the effect allele flips the sign of β relative to the aligned outcome.
Fix: Check the effect allele column for each source; the sources table is in the reference section.
Far fewer instruments after clumping than significant SNPs
Cause: ld_clump drops SNPs that are absent from the reference panel. In this example 132 of 3,060 significant SNPs were missing, and the smallest of them had P = 4.3e-127.
Fix: First check which SNPs are not in the panel using the .bim file, and report the number and the smallest P in the methods. Check that the population matches before changing panels.
ld_clump fails or times out repeatedly when bfile is not given, or asks for a token
Cause: Without bfile, ld_clump calls the OpenGWAS API. It needs a token and is limited by points (12 points per /ld/clump call).
Fix: Switch to local plink clumping: rename the data frame columns to rsid and pval, and set bfile to the reference panel prefix without .bed. The local code is in step 2.
unused argument (access_token = NULL)
Cause: The code is copied from a tutorial older than 2023, when the argument was renamed to opengwas_jwt. The variable name IUEUGWAS_TOKEN in some Chinese posts is wrong; ieugwasr reads only OPENGWAS_JWT.
Fix: Delete the access_token argument. Write the token to OPENGWAS_JWT, and it is read from the environment automatically.
Error in if (nrow(d) == 0) return(NULL) : argument is of length zero
Cause: The API returned nothing: the token failed, the dataset ID is wrong, or there are no SNPs at this threshold.
Fix: Run user() to rule out the token, then check the dataset ID with gwasinfo(id).
429 Too Many Requests
Cause: The points for the 10-minute window are used up. Repeated 429 responses can get the account and IP blocked for up to a week.
Fix: Wait until the time given in the Retry-After header; for batch jobs, switch to local files.
Fewer SNPs than expected after harmonisation, or the exported supplementary table does not match nsnp in the results
Cause: Palindromic SNPs with frequency between 0.42 and 0.58 cannot have their strand inferred, so they are marked mr_keep = FALSE. In this example rs2954029 and rs964184 were removed. Removed rows stay in the data frame, so an export without filtering includes extra rows.
Fix: Filter with dat <- dat[dat$mr_keep, ] before exporting, and report the swap and removal counts from attr(dat, "log") in the supplement.
Some instruments are missing from the outcome data
Cause: Different GWAS cover different SNPs, so some instruments may be absent from the outcome.
Fix: Online, use proxies = TRUE in extract_outcome_data. Offline, find proxies with r² ≥ 0.8 using local plink. See the choice on palindromic SNPs and the action parameter.
format_data warns about duplicate rsIDs and keeps only the first row
Cause: Multi-allelic sites in files such as FinnGen create duplicate rsIDs. In this example rs7534572 was duplicated.
Fix: First match rows on ref and alt against the exposure alleles and keep the correct row, then pass the data to format_data.
Every SNP has exactly the same F value
Cause: When numeric columns formatted as General in Excel are saved as CSV, β and SE can be lost or become 0, and very small P values are truncated.
Fix: Read and write the raw files with R or command-line tools throughout; do not pass them through Excel.
The computed R² is orders of magnitude smaller than the literature
Cause: Some formulas omit the square of β, or plug in β in mg/dL directly. The formula 2·EAF·(1−EAF)·β² holds only when β is in standard-deviation units.
Fix: Use the formula in step 3, which includes SE and sample size and is less sensitive to units.
The OR for a binary outcome is close to 1, or β is very small
Cause: Neale lab UKB results use linear regression for binary phenotypes, so β is on the probability scale. Using it directly as a log OR gives an OR close to 1.
Fix: Convert to an approximate log OR with β/[u(1−u)], where u is the case proportion.
MR-PRESSO warns Outlier test unstable … The current precision is <0.077
Cause: NbDistribution is less than 20 times the SNP count, so the precision of the outlier test is insufficient. The outlier-test P values are Bonferroni-corrected for the number of SNPs. In this example, 77 SNPs with NbDistribution = 1000 gave this warning after 66 seconds.
Fix: Increase NbDistribution to at least 20 times the SNP count. In this example, 2000 took 138 seconds and removed the warning. Run time grows with the SNP count and NbDistribution.
Reproducing a paper gives different P values, though OR and confidence intervals are close
Cause: OpenGWAS datasets and packages such as TwoSampleMR are updated over time.
Fix: State package versions and download dates in the paper, and keep the data files and scripts used.
Sources
- OpenGWAS API documentation: authentication, allowance and cost per endpoint — Token valid for 14 days; 100,000 credits per 10 minutes for every tier; credits for /tophits, /ld/clump and /gwasinfo/files; 429 blocking rules
- OpenGWAS dataset page (ieu-a-300) — Website VCF downloads limited to 20 datasets per 24 hours, links valid for 2 hours
- ieugwasr: Guide and Running local LD operations — OPENGWAS_JWT, get_opengwas_jwt, user; bfile and plink_bin for local ld_clump; 1kg.v3.tgz
- TwoSampleMR changelog — 0.7.12 (2026-10-08); 0.6.0 moved to the CRAN ieugwasr; 0.6.20 requires ieugwasr ≥ 1.1.0
- STROBE-MR checklist — 20 reporting items; this page cites items 5, 7, 9, 10d, 11 and 13
- Burgess S, et al. Guidelines for performing Mendelian randomization investigations: update for summer 2023. Wellcome Open Res — Direction of bias from sample overlap, table of method assumptions, MR-PRESSO false positives, positive controls and leave-one-out
- FinnGen: Access results and R13 data description — DF13 public on 2026-06-02; alt is the effect allele; GRCh38; manifest and tabix indexes
- Pan-UKB:Per-phenotype files — neglog10_pval columns, alt as effect allele, GRCh37, low_confidence flags
- Neale lab UK Biobank GWAS (GitHub) — Round 2 uses Hail linear regression
- GWAS Catalog summary statistics GCST003116 (CARDIoGRAMplusC4D 2015) — Outcome data tested on this page; hm_ columns of the harmonised file
- GLGC 2013 lipid GWAS results — Exposure data tested on this page; A1 is the effect allele
- MR-PRESSO (GitHub rondolab) — Constraint between NbDistribution and SNP count, Outlier test unstable warning (checked in the source code)
- Burgess S, Davies NM, Thompson SG. Bias due to participant overlap in two-sample Mendelian randomization. Genet Epidemiol 2016 — Bias from sample overlap and its relation to the F statistic
- Burgess S, Labrecque JA. Mendelian randomization with a binary exposure variable. Eur J Epidemiol 2018 — Interpreting estimates for a binary exposure and multiplying by ln2
- Lloyd-Jones LR, et al. Transformation of summary statistics from linear mixed model association on all-or-none traits to odds ratio. Genetics 2018 — Converting linear-model β to logOR
- Experience post: CSDN, "MR data download error: Status code from OpenGWAS API: 401" — Experience post: 401 error and token reset
- Experience post: CSDN, "MR LD clumping fails? A local LD clumping method" — Experience post: column names and bfile path for local clumping
- Experience post: CSDN, "Reproducing an MR paper in R" — Experience post: same data and code give different P values; old access_token argument
- Experience post: CSDN, "Mendelian randomization: a pitfall nobody mentions" — Experience post: numbers turn into 0 after saving from Excel to CSV
- Experience post: CSDN, "GWAS data download explained (1)" — Experience post: ES/SE/LP/AF fields of IEU VCFs