| Title: | Mendelian Randomization Accounting for Pleiotropy and Sample Structure |
|---|---|
| Description: | Implements the MR-APSS approach to test for the causal effects between an exposure and an outcome disease. MR-APSS is a unified approach to Mendelian Randomization accounting for polygenicity, pleiotropy and sample structure using genome-wide summary statistics. Specifically, MR-APSS uses a background-foreground model to characterize both SNP-exposure effects and SNP-outcome effects estimates, where the background model accounts for confounding from genetic correlation and sample structure and the foreground model captures the valid signal for causal inference. |
| Authors: | Xianghong HU [aut, cre] (ORCID: <https://orcid.org/0000-0001-5260-3936>) |
| Maintainer: | Xianghong HU <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-10-08 15:38:15 UTC |
| Source: | https://github.com/remlapmot/MR-APSS |
The 2x2 matrix capturing the effects of sample structure for the example analysis of BMI (UK Biobank) on type 2 diabetes, as returned by [est_paras()].
CC
A 2 by 2 numeric matrix. Entry '[1, 1]' corresponds to the exposure, entry '[2, 2]' to the outcome and the off-diagonal entries to the correlation induced by sample overlap.
[Omega], [MRdat]
Peform LD clumping, to prune SNPs in LD within a window. Keep the most significant ones.
clump( dat, IV.Threshold = 5e-05, SNP_col = "SNP", pval_col = "pval.exp", clump_kb = 1000, clump_r2 = 0.001, clump_p = 0.999, pop = "EUR", bfile = NULL, plink_bin = NULL )clump( dat, IV.Threshold = 5e-05, SNP_col = "SNP", pval_col = "pval.exp", clump_kb = 1000, clump_r2 = 0.001, clump_p = 0.999, pop = "EUR", bfile = NULL, plink_bin = NULL )
dat |
a data frame must have columns with information about SNPs and p values |
IV.Threshold |
p-value threshold for IV selection. SNPs with p value larger than 'IV.Threshold' are discarded before clumping. Default = 5e-05. |
SNP_col |
column with SNP rsid. The default is '"SNP"' |
pval_col |
column with p value. The default is '"pval"' |
clump_kb |
clumping window in kb. Default is 1000. |
clump_r2 |
clumping r2 threshold. Default is 0.001. |
clump_p |
clumping significance level for index variants. Default = 5e-05 |
pop |
super-population to use as the LD reference panel when clumping with the remote API. One of '"EUR"', '"SAS"', '"EAS"', '"AFR"' or '"AMR"'. Default = '"EUR"'. |
bfile |
bfile as LD reference panel. If this is provided, then will use local PLINK. Default = NULL. |
plink_bin |
path to local plink binary. Default = NULL. |
data frame of clumped SNPs
A function harmonizing datasets and estimate background parameters by LD score regression.
est_paras( dat1, dat2, trait1.name = "exposure", trait2.name = "outcome", LDSC = TRUE, h2.fix.intercept = FALSE, ldscore.dir = NULL, ld = NULL, M = NULL )est_paras( dat1, dat2, trait1.name = "exposure", trait2.name = "outcome", LDSC = TRUE, h2.fix.intercept = FALSE, ldscore.dir = NULL, ld = NULL, M = NULL )
dat1 |
formatted GWAS summary-level data for trait 1. |
dat2 |
formatted GWAS summary-level data for trait 2. |
trait1.name |
specify the name of trait 1, default 'exposure'. |
trait2.name |
specify the name of trait 2, default 'outcome'. |
LDSC |
logical, whether to run LD score regression, default 'TRUE'. If 'FALSE', the function will not give the parameter estimates but will do harmonizing. |
h2.fix.intercept |
logical, whether to fix LD score regression intercept to 1, default 'FALSE'. |
ldscore.dir |
specify the path to the LD score files. |
ld |
specify the data.frame for the ld scores of SNPs if available and setting ldscore.dir =NULL. |
M |
specify the number of SNPs used for calculating LD score. |
List with the following elements:
Homonised data set
the estimated C matrix capturing the effects of sample structure
the estimated variance-covariance matrix for polygenic effects
Format GWAS summary data for MR-APSS. This function is adapted from the format_data() function in MRCIEU/TwoSampleMR.
format_data( dat, snps.merge = w_hm3.snplist, snps.remove = MHC.SNPs, snp_col = "SNP", b_col = "b", or_col = "or", se_col = "se", freq_col = "freq", A1_col = "A1", A2_col = "A2", p_col = "p", ncase_col = "ncase", ncontrol_col = "ncontrol", n_col = "n", n = NULL, z_col = "z", info_col = "INFO", log_pval = FALSE, chi2_max = NULL, min_freq = 0.05 )format_data( dat, snps.merge = w_hm3.snplist, snps.remove = MHC.SNPs, snp_col = "SNP", b_col = "b", or_col = "or", se_col = "se", freq_col = "freq", A1_col = "A1", A2_col = "A2", p_col = "p", ncase_col = "ncase", ncontrol_col = "ncontrol", n_col = "n", n = NULL, z_col = "z", info_col = "INFO", log_pval = FALSE, chi2_max = NULL, min_freq = 0.05 )
dat |
data.frame with at least SNP A1 A2 signed statistics for calculating z scores and sample size. |
snps.merge |
data.frame with SNPs to extract. The data frame must have headers: SNP A1 and A2. For example, the hapmap3 SNP list. |
snps.remove |
a set of SNPs that needed to be removed. For example, SNPs in MHC region. |
snp_col |
name of a column with rs numbers. The default is |
b_col |
name of a column with effect sizes. The default is |
or_col |
name of a column with odds ratios. The default is |
se_col |
name of a column with standard errors. The default is |
freq_col |
name of a column with effect allele frequencies. The default is |
A1_col |
name of a column with effect alleles. The default is |
A2_col |
name of a column with the other alleles. The default is |
p_col |
name of a column with p-values. The default is |
ncase_col |
name of a column with the number of cases. The default is |
ncontrol_col |
name of a column with the number of controls. The default is |
n_col |
name of a column with sample sizes. The default is |
n |
sample size. If the column for sample size is not available, users can use argument "n" to specify the total sample size for each SNP. |
z_col |
name of a column with z scores. The default is |
info_col |
name of a column with imputation INFO. The default is |
log_pval |
logical, whether the p-value is in -log10 scale. The default is |
chi2_max |
SNPs with tested chi^2 statistics large than chi2_max will be removed. The default is |
min_freq |
SNPs with allele frequency less than min_freq will be removed. The default is |
a data frame with headers: SNP: rs number; A1: effect allele; A2: the other allele; Z: Z score; N: sample size; chi2: chi-square statistics; P: p-value.
rs numbers of SNPs lying in the major histocompatibility complex (MHC) region of chromosome 6. The extended LD structure of this region makes it unsuitable for LD score regression, so these SNPs are removed by [format_data()] by default.
MHC.SNPsMHC.SNPs
A character vector of 109503 rs numbers.
[format_data()]
Fits the MR-APSS background-foreground model in which the foreground effects on the exposure and on the outcome are allowed to be correlated. This is the workhorse called by [MR_fix_rf()] and [sensitivity()].
MR_EM_fix_rf_func( data = NULL, beta = NULL, Sigma = NULL, pi0 = NULL, fix.beta = TRUE, fix.r = TRUE, r = 0, C = diag(2), Omega = matrix(0, 2, 2), tol = 1e-06, Threshold = 1, ELBO = FALSE )MR_EM_fix_rf_func( data = NULL, beta = NULL, Sigma = NULL, pi0 = NULL, fix.beta = TRUE, fix.r = TRUE, r = 0, C = diag(2), Omega = matrix(0, 2, 2), tol = 1e-06, Threshold = 1, ELBO = FALSE )
data |
data.frame that at least contains the following columns: b.exp b.out se.exp se.out L2. L2: LD score. |
beta |
initial value for the causal effect, default 'NULL' uses 0. |
Sigma |
initial value for Sigma, the variance-covariance matrix of the foreground effects. Default 'NULL' uses the default initialization procedure. |
pi0 |
initial value for pi0, default 'NULL' uses 0.5. |
fix.beta |
logical, whether to hold 'beta' fixed at its initial value. Used to fit the null model in the likelihood ratio test. Default 'TRUE'. |
fix.r |
logical, whether to hold the foreground correlation 'r' fixed. Default 'TRUE'. |
r |
the correlation between IV strength and direct effect in the foreground model. Default '0'. |
C |
the estimated C matrix capturing the effects of sample structure. Default 'diag(2)'. |
Omega |
the estimated variance-covariance matrix of polygenic effects. Default 'matrix(0, 2, 2)'. |
tol |
tolerance for the relative change in the likelihood. Default '1e-06'. |
Threshold |
the modified IV selection threshold used to correct for selection bias. 'Threshold = 1' disables the correction. Default '1'. |
ELBO |
logical, whether to monitor the evidence lower bound instead of the maximum likelihood. Default 'FALSE'. |
a list with the following elements:
causal effect estimate
estimated variance-covariance matrix of the foreground effects
the probability of an SNP with foreground signals after selection
the maximised log likelihood
the IV selection threshold used
A function for causal effect estimation and inference in sensitivity analysis.
MR_fix_rf( MRdat = NULL, exposure = "exposure", outcome = "outcome", pi0 = NULL, Sigma = NULL, r = 0, C = matrix(c(1, 0, 0, 1), 2, 2), Omega = matrix(0, 2, 2), Cor.SelectionBias = TRUE, tol = 1e-08 )MR_fix_rf( MRdat = NULL, exposure = "exposure", outcome = "outcome", pi0 = NULL, Sigma = NULL, r = 0, C = matrix(c(1, 0, 0, 1), 2, 2), Omega = matrix(0, 2, 2), Cor.SelectionBias = TRUE, tol = 1e-08 )
MRdat |
data.frame at least contains the following columns: b.exp b.out se.exp se.out L2 Threshold. L2:LD score, Threshold: modified IV selection threshold for correction of selection bias |
exposure |
exposure name |
outcome |
outcome name |
pi0 |
initial value for pi0, default 'NULL' will use the default initialize procedure. |
Sigma |
initial value for Sigma (the variance-covariance matrix for forground effects), default 'NULL'will use the default initialize procedure. |
r |
The value of r (correlation between IV strength and direct effect in the foreground model), default '0', r is fixed. |
C |
the estimated C matrix capturing the effects of sample structure. default 'diag(2)'. |
Omega |
the estimated variance-covariance matrix of polygenic effects. default 'matrix(0,2,2)'. |
Cor.SelectionBias |
logical, whether to correct selection bias or not. If FALSE, the model won't correct for selection bias. |
tol |
tolerence, default '1e-12'. |
a list with the following elements:
exposure of interest
outcome of interest
causal effect estimate
standard error
p-value
library(MRAPSS) exposure = "BMI" outcome = "T2D" Threshold = 5e-05 # IV selection Threshold data(C) data(Omega) data(MRdat) MRres = MR_fix_rf(MRdat, exposure = "BMI", outcome = "T2D", r=0, C = C, Omega = Omega , Cor.SelectionBias = TRUE)library(MRAPSS) exposure = "BMI" outcome = "T2D" Threshold = 5e-05 # IV selection Threshold data(C) data(Omega) data(MRdat) MRres = MR_fix_rf(MRdat, exposure = "BMI", outcome = "T2D", r=0, C = C, Omega = Omega , Cor.SelectionBias = TRUE)
MR-APSS: a unified approach to Mendelian Randomization accounting for Pleiotropy and Sample Structure using genome-wide summary statistics. MA-APSS uses a variational EM algorithm for the estimation of parameters. MR-APSS uses likelihood ratio test for inference.
MRAPSS( MRdat = NULL, exposure = "exposure", outcome = "outcome", pi0 = NULL, sigma.sq = NULL, tau.sq = NULL, C = matrix(c(1, 0, 0, 1), 2, 2), Omega = matrix(0, 2, 2), Cor.SelectionBias = TRUE, tol = 1e-08, ELBO = FALSE )MRAPSS( MRdat = NULL, exposure = "exposure", outcome = "outcome", pi0 = NULL, sigma.sq = NULL, tau.sq = NULL, C = matrix(c(1, 0, 0, 1), 2, 2), Omega = matrix(0, 2, 2), Cor.SelectionBias = TRUE, tol = 1e-08, ELBO = FALSE )
MRdat |
data.frame at least contains the following columns: b.exp b.out se.exp se.out L2 Threshold. L2:LD score, Threshold: modified IV selection threshold for correction of selection bias |
exposure |
exposure name |
outcome |
outcome name |
pi0 |
initial value for pi0, default 'NULL' will use the default initialize procedure. |
sigma.sq |
initial value for sigma.sq , default 'NULL'will use the default initialize procedure. |
tau.sq |
initial value for tau.sq , default 'NULL' will use the default initialize procedure. |
C |
the estimated C matrix capturing the effects of sample structure. default 'diag(2)'. |
Omega |
the estimated variance-covariance matrix of polygenic effects. default 'matrix(0,2,2)'. |
Cor.SelectionBias |
logical, whether to correct selection bias or not. If FALSE, the model won't correct for selection bias. |
tol |
tolerence, default '1e-08'. |
ELBO |
logical, whether to the evidence lower bound or not. If 'FALSE', check the maximum likelihood instead. default 'FALSE'. |
a list with the following elements:
Input data frame
exposure of interest
outcome of interest
causal effect estimate
standard error
p-value
variance of forground exposure effect
variance of forground outcome effect
The probability of an SNP with foreground signals after selection
Posterior estimates of latent varaibles
"MR-APSS"
library(MRAPSS) exposure = "BMI" outcome = "T2D" Threshold = 5e-05 # IV selection Threshold data(C) data(Omega) data(MRdat) MRres = MRAPSS(MRdat, exposure = "BMI", outcome = "T2D", C = C, Omega = Omega , Cor.SelectionBias = TRUE) MRplot(MRres, exposure = "BMI", outcome = "T2D")library(MRAPSS) exposure = "BMI" outcome = "T2D" Threshold = 5e-05 # IV selection Threshold data(C) data(Omega) data(MRdat) MRres = MRAPSS(MRdat, exposure = "BMI", outcome = "T2D", C = C, Omega = Omega , Cor.SelectionBias = TRUE) MRplot(MRres, exposure = "BMI", outcome = "T2D")
Clumped and harmonized GWAS summary statistics for BMI (UK Biobank) and type 2 diabetes, ready to be passed to [MRAPSS()].
MRdatMRdat
A data frame with 1227 rows and 11 columns:
rs number
effect allele
the other allele
SNP effect on the exposure
SNP effect on the outcome
standard error of 'b.exp'
standard error of 'b.out'
p-value for the SNP-exposure association
p-value for the SNP-outcome association
LD score
modified IV selection threshold used to correct for selection bias
[C], [Omega]
Visualize the MR-APSS analysis results
MRplot(MRres, exposure = "trait 1", outcome = "trait 2")MRplot(MRres, exposure = "trait 1", outcome = "trait 2")
MRres |
MR-APSS fit results |
exposure |
exposure name |
outcome |
outcome name |
a scatter plot of SNP-exposure effect and SNP-outcome effect with the causal effect and 95% confidence interval.
The 2x2 variance-covariance matrix of the polygenic (background) effects for the example analysis of BMI (UK Biobank) on type 2 diabetes, as returned by [est_paras()].
OmegaOmega
A 2 by 2 numeric matrix. The diagonal entries are the per-SNP heritabilities of the exposure and the outcome and the off-diagonal entries are the per-SNP genetic covariance.
[C], [MRdat]
Refits MR-APSS over a grid of values for 'r', the correlation between IV strength and direct effect in the foreground model, and summarises how the causal effect estimate varies with 'r'. The grid runs from 0 to the value of 'r' implied by an unconstrained fit of the foreground variance-covariance matrix.
sensitivity( MRdat = NULL, Omega = NULL, C = NULL, exposure = "exposure", outcome = "outcome" )sensitivity( MRdat = NULL, Omega = NULL, C = NULL, exposure = "exposure", outcome = "outcome" )
MRdat |
data.frame that at least contains the following columns: b.exp b.out se.exp se.out L2 Threshold. L2: LD score, Threshold: modified IV selection threshold for correction of selection bias. |
Omega |
the estimated variance-covariance matrix of polygenic effects. |
C |
the estimated C matrix capturing the effects of sample structure. |
exposure |
exposure name. |
outcome |
outcome name. |
a list with the following elements:
data frame with columns r, beta, se and pval, one row per value of r
a ggplot object showing the causal effect estimate against r
The HapMap 3 SNP list distributed with LDSC, used by [format_data()] as the default set of SNPs to retain.
w_hm3.snplistw_hm3.snplist
A data frame with 1217311 rows and 3 columns:
rs number
effect allele
the other allele
[format_data()]