Package: TwoSampleMR 0.7.9

Gibran Hemani

TwoSampleMR: Two Sample MR Functions and Interface to MRC Integrative Epidemiology Unit OpenGWAS Database

A package for performing Mendelian randomization using GWAS summary data. It uses the IEU OpenGWAS database <https://opengwas.io> to automatically obtain data, and a wide range of methods to run the analysis.

Authors:Gibran Hemani [aut, cre], Philip Haycock [aut], Jie Zheng [aut], Tom Gaunt [aut], Ben Elsworth [aut], Tom Palmer [aut], Marina Vabistsevits [ctb]

TwoSampleMR_0.7.9.tar.gz
TwoSampleMR_0.7.9.zip(r-4.7)TwoSampleMR_0.7.9.zip(r-4.6)TwoSampleMR_0.7.9.zip(r-4.5)
TwoSampleMR_0.7.9.tgz(r-4.6-any)TwoSampleMR_0.7.9.tgz(r-4.5-any)
TwoSampleMR_0.7.9.tar.gz(r-4.7-any)TwoSampleMR_0.7.9.tar.gz(r-4.6-any)
TwoSampleMR_0.7.9.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
TwoSampleMR/json (API)

# Install 'TwoSampleMR' in R:
install.packages('TwoSampleMR', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/mrcieu/twosamplemr/issues

Pkgdown/docs site:https://mrcieu.github.io

On CRAN:

Conda:

11.90 score 551 stars 2 packages 2.6k scripts 114 exports 85 dependencies

Last updated from:3d119f20d6. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK285
source / vignettesOK397
linux-release-x86_64OK343
macos-release-arm64OK188
macos-oldrel-arm64OK250
windows-develOK273
windows-releaseOK396
windows-oldrelOK237
wasm-releaseOK182

Exports:%>%add_metadataadd_rsqallele_frequencyavailable_outcomesclump_datacombine_all_mrresultscombine_datacontingencyconvert_outcome_to_exposuredat_to_MRInputdat_to_RadialMRdefault_parametersdirectionality_testeffective_nenrichmentenrichment_method_listestimate_trait_sdextract_instrumentsextract_outcome_datafishers_combined_testforest_plotforest_plot_1_to_manyformat_1_to_manyformat_aries_mqtlformat_dataformat_gtex_eqtlformat_gwas_catalogformat_metab_qtlsformat_mr_resultsformat_proteomic_qtlsgenerate_odds_ratiosget_p_from_r2nget_population_allele_frequencyget_r_from_bsenget_r_from_lorget_r_from_pnget_seharmonise_dataharmonise_ld_datIsqld_matrixldsc_h2ldsc_rgmake_datmrmr_density_plotmr_egger_regressionmr_egger_regression_bootstrapmr_forest_plotmr_funnel_plotmr_gripmr_heterogeneitymr_ivwmr_ivw_femr_ivw_mremr_ivw_radialmr_leaveoneoutmr_leaveoneout_plotmr_medianmr_meta_fixedmr_meta_fixed_simplemr_meta_randommr_method_listmr_modemr_moemr_penalised_weighted_medianmr_pleiotropy_testmr_rapsmr_reportmr_ruckermr_rucker_bootstrapmr_rucker_cooksdistancemr_rucker_jackknifemr_scatter_plotmr_signmr_simple_medianmr_simple_modemr_simple_mode_nomemr_singlesnpmr_steigermr_steiger2mr_two_sample_mlmr_uwrmr_wald_ratiomr_weighted_medianmr_weighted_modemr_weighted_mode_nomemr_wrappermv_basicmv_extract_exposuresmv_extract_exposures_localmv_harmonise_datamv_ivwmv_lasso_feature_selectionmv_multiplemv_residualmv_subsetpower_pruneread_exposure_dataread_outcome_datarun_mr_pressorun_mrmixsize.prunesort_1_to_manysplit_exposuresplit_outcomestandardise_unitssteiger_filteringsteiger_sensitivitysubset_on_methodtrimweighted_medianweighted_median_bootstrap

Dependencies:askpassbase64encbslibcachemclicodetoolscowplotcpp11crosstalkcurldata.tabledigestdplyrevaluatefarverfastmapfontawesomeforeachfsgenericsggplot2glmnetglueGPArotationgridExtragtablehighrhtmltoolshtmlwidgetshttrieugwasrisobanditeratorsjquerylibjsonliteknitrlabelinglaterlatticelazyevallifecyclemagrittrMASSMatrixmemoisemimemnormtMRMixMRPRESSOnlmeopensslotelpbapplypillarpkgconfigplotlypromisespsychpurrrR6RadialMRrappdirsRColorBrewerRcppRcppEigenrlangrmarkdownS7sassscalesshapestringistringrsurvivalsystibbletidyrtidyselecttinytexutf8vctrsviridisLitewithrxfunyaml

Perform MR
Introduction | MR methods | Sensitivity analyses | Heterogeneity statistics | Horizontal pleiotropy | Single SNP analysis | Leave-one-out analysis | Plots | Scatter plot | Forest plot | Forest plot with categories | RadialMR outlier example | MR-PRESSO outlier example | Leave-one-out plot | Funnel plot | 1-to-many forest plot | Step 1: Generate 1-to-many MR results | Step 2: Make the 1-to-many forest plot | Example 1. Effect of multiple risk factors on coronary heart disease | Example 2. MR results for multiple MR methods grouped by multiple exposures | Example 3. Stratify results on a grouping variable | Example 4. Effect of BMI on 103 diseases | MR-RAPS: Many weak instruments analysis | MR-GRIP | Reports | MR Steiger directionality test | Multivariable MR | Note about multivariable methods | Note about visualisation | Using your own summary data | From local files | From data frames | Mixing local and OpenGWAS data | Converting to MVMR format | MR estimates when instruments are correlated | MR-MoE: Using a mixture of experts machine learning approach | Post MR results management | Split outcome names | Split exposure names | Generate odds ratios with 95% confidence intervals | Subset on method | Combine all results | References

Last update: 2026-06-10
Started: 2020-01-11

Exposure data
Introduction | Reading in from a file | Example 1: The default column names are used | Example 2: The text file has non-default column names | Using an existing data frame | Obtaining instruments from existing catalogues | GWAS catalog | Metabolites | Proteins | Gene expression levels | DNA methylation levels | IEU OpenGWAS database | Clumping

Last update: 2026-05-15
Started: 2020-01-11

Introduction
Background | Installation | Overview | Authentication | References

Last update: 2026-05-15
Started: 2020-01-11

Major changes to the IEU GWAS resources for 2020
What has changed | Dataset IDs | Authentication | UKBiobank data has been curated | All data is now harmonised | LD reference panel is now harmonised | Instrument lists are up-to-date | dbSNP rs IDs | Everything is faster | What is new | Browse available datasets online | Chromosome and position | INDELs are retained | Multi-allelic variants are retained | More data | Error messages are more informative | Easier programmatic access to the database | Local LD operations | Access the data directly | Connect the data to different analytical tools | Key links | How to request new data

Last update: 2026-05-04
Started: 2020-01-11

Outcome data
Available studies in IEU GWAS database | Extracting particular SNPs from particular studies | LD proxies | Using local GWAS summary data | Outcome data format | More advanced use of local data

Last update: 2026-05-04
Started: 2020-01-11

Harmonise data
Introduction | Dealing with strand issues | Correct, unambiguous | Incorrect reference, unambiguous | Ambiguous | Palindromic SNP, inferrable | Palindromic SNP, not inferrable | Options | Drop duplicate exposure-outcome summary sets

Last update: 2025-08-27
Started: 2020-01-11

Readme and manuals

Help Manual

Help pageTopics
Add meta data to extracted dataadd_metadata
Estimate r-squared of each associationadd_rsq
Estimate allele frequency from SNPallele_frequency
Get list of studies with available GWAS summary statistics through APIavailable_outcomes
Perform LD clumping on SNP dataclump_data
Combine all mr resultscombine_all_mrresults
Combine datacombine_data
Obtain 2x2 contingency table from marginal parameters and odds ratiocontingency
Convert outcome data to exposure dataconvert_outcome_to_exposure
Convert TwoSampleMR format to MendelianRandomization formatdat_to_MRInput
Convert dat to RadialMR formatdat_to_RadialMR
List of parameters for use with MR functionsdefault_parameters
Perform MR Steiger test of directionalitydirectionality_test
Estimate the effective sample size in a case control studyeffective_n
Perform enrichment analysisenrichment
Get list of available p-value enrichment methodsenrichment_method_list
Estimate trait SD by obtaining beta estimates from z-scores and finding the ratio with original beta valuesestimate_trait_sd
Find instruments for use in MR from the OpenGWAS databaseextract_instruments
Supply the output from 'read_exposure_data()' and all the SNPs therein will be queried against the requested outcomes in remote database using API.extract_outcome_data
Fisher's combined testfishers_combined_test
Forest plot for multiple exposures and multiple outcomesforest_plot
1-to-many forest plotforest_plot_1_to_many
A basic forest plotforest_plot_basic2
Format MR results for a 1-to-many forest plotformat_1_to_many
Get data from methylation QTL resultsformat_aries_mqtl
Read exposure or outcome dataformat_data
Get data from eQTL catalog into correct formatformat_gtex_eqtl
Get data selected from GWAS catalog into correct formatformat_gwas_catalog
Get data from metabolomic QTL resultsformat_metab_qtls
Format MR results for forest plotformat_mr_results
Get data from proteomic QTL resultsformat_proteomic_qtls
Generate odds ratiosgenerate_odds_ratios
Calculate p-value from R-squared and sample sizeget_p_from_r2n
Estimate the allele frequency in population from case/control summary dataget_population_allele_frequency
Estimate R-squared from beta, standard error and sample sizeget_r_from_bsen
Estimate proportion of variance of liability explained by SNP in general populationget_r_from_lor
Calculate variance explained from p-values and sample sizeget_r_from_pn
Get SE from effect size and p-valueget_se
Harmonise the alleles and effects between the exposure and outcomeharmonise_data
Harmonise LD matrix against summary dataharmonise_ld_dat
I-squared calculationIsq
Get LD matrix for list of SNPsld_matrix
Univariate LDSCldsc_h2
Bivariate LDSCldsc_rg
Convenient function to create a harmonised datasetmake_dat
Perform all Mendelian randomization testsmr
Density plotmr_density_plot
Egger's regression for Mendelian randomizationmr_egger_regression
Run bootstrap to generate standard errors for MRmr_egger_regression_bootstrap
Forest plotmr_forest_plot
Funnel plotmr_funnel_plot
MR-GRIP: a modified MR-Egger model with the Genotype Recoding Invariance Propertymr_grip
Get heterogeneity statisticsmr_heterogeneity
Inverse variance weighted regressionmr_ivw
Inverse variance weighted regression (fixed effects)mr_ivw_fe
Inverse variance weighted regression (multiplicative random effects model)mr_ivw_mre
Radial IVW analysismr_ivw_radial
Leave one out sensitivity analysismr_leaveoneout
Plot results from leaveoneout analysismr_leaveoneout_plot
MR median estimatorsmr_median
Perform 2 sample IV using fixed effects meta analysis and delta method for standard errorsmr_meta_fixed
Perform 2 sample IV using simple standard errormr_meta_fixed_simple
Perform 2 sample IV using random effects meta analysis and delta method for standard errorsmr_meta_random
Get list of available MR methodsmr_method_list
MR mode estimatorsmr_mode
Mixture of expertsmr_moe
Penalised weighted median MRmr_penalised_weighted_median
Test for horizontal pleiotropy in MR analysismr_pleiotropy_test
Robust adjusted profile scoremr_raps
Generate MR reportmr_report
MR Rucker frameworkmr_rucker
Run rucker with bootstrap estimatesmr_rucker_bootstrap
MR Rucker with outliers automatically detected and removedmr_rucker_cooksdistance
Run rucker with jackknife estimatesmr_rucker_jackknife
Create scatter plot with fitted lines showing the causal effect estimate for different MR estimatorsmr_scatter_plot
MR sign testmr_sign
Simple median methodmr_simple_median
MR simple mode estimatormr_simple_mode
MR simple mode estimator (NOME)mr_simple_mode_nome
Perform 2 sample MR on each SNP individuallymr_singlesnp
MR Steiger test of directionalitymr_steiger
MR Steiger test of directionalitymr_steiger2
Maximum likelihood MR methodmr_two_sample_ml
Unweighted regressionmr_uwr
Perform 2 sample IV using Wald ratio.mr_wald_ratio
Weighted median methodmr_weighted_median
MR weighted mode estimatormr_weighted_mode
MR weighted mode estimator (NOME)mr_weighted_mode_nome
Perform full set of MR analysesmr_wrapper
Perform basic multivariable MRmv_basic
Extract exposure variables for multivariable MRmv_extract_exposures
Attempt to perform MVMR using local datamv_extract_exposures_local
Harmonise exposure and outcome for multivariable MRmv_harmonise_data
Perform IVW multivariable MRmv_ivw
Apply LASSO feature selection to mvdat objectmv_lasso_feature_selection
Perform IVW multivariable MRmv_multiple
Perform basic multivariable MRmv_residual
Perform multivariable MR on subset of featuresmv_subset
Power prunepower_prune
Read exposure dataread_exposure_data
Read outcome dataread_outcome_data
Wrapper for MR-PRESSOrun_mr_presso
Perform MRMix analysis on harmonised dat objectrun_mrmix
Size prunesize.prune
Sort results for 1-to-many forest plotsort_1_to_many
Split exposure columnsplit_exposure
Split outcome columnsplit_outcome
Try to standardise continuous traits to be in standard deviation unitsstandardise_units
Steiger filtering functionsteiger_filtering
Evaluate the Steiger test's sensitivity to measurement errorsteiger_sensitivity
Subset MR-results on methodsubset_on_method
Trim function to remove leading and trailing blank spacestrim
Weighted median methodweighted_median
Calculate standard errors for weighted median method using bootstrapweighted_median_bootstrap