Title: | An R Package for Mendelian Randomization in the mediation setting |
---|---|
Description: | A Bayesian framework for Mendelian Randomization in the mediation setting. |
Authors: | Jingshu Wang [aut], Ethan Lewis [aut], Zixuan Wu [aut, cre] |
Maintainer: | Zixuan Wu <[email protected]> |
License: | What license is it under? |
Version: | 1.0 |
Built: | 2025-01-17 06:39:20 UTC |
Source: | https://github.com/ZixuanWu1/MrMediation |
A Bayesian framework for Mendelian Randomization in the mediation setting.
The DESCRIPTION file:
Package: | MrMediation |
Type: | Package |
Title: | An R Package for Mendelian Randomization in the mediation setting |
Version: | 1.0 |
Date: | 2022-10-06 |
Authors@R: | c(person("Jingshu", "Wang", email = "[email protected]", role = c("aut")), person("Ethan", "Lewis", email = "[email protected]", role = c("aut")), person("Zixuan", "Wu", email = "[email protected]", role = c("aut", "cre"))) |
Description: | A Bayesian framework for Mendelian Randomization in the mediation setting. |
License: | What license is it under? |
Imports: | Rcpp (>= 1.0.9), coda, doParallel, foreach, ggplot2, stats, magic |
LinkingTo: | Rcpp, RcppArmadillo |
RoxygenNote: | 7.2.1 |
Encoding: | UTF-8 |
Repository: | https://mrcieu.r-universe.dev |
RemoteUrl: | https://github.com/ZixuanWu1/MrMediation |
RemoteRef: | HEAD |
RemoteSha: | 2aad8accd4fa736894760cf107701e498883e821 |
Author: | Jingshu Wang [aut], Ethan Lewis [aut], Zixuan Wu [aut, cre] |
Maintainer: | Zixuan Wu <[email protected]> |
Index of help topics:
BayesMediation BayesMediation MrMediation-package An R Package for Mendelian Randomization in the mediation setting gibbs_sampler Perform Gibbs sampling for mediation MR without correlation gibbs_sampler_with_corr Perform Gibbs sampling for mediation MR with correlation gibbs_wrapper Gibbs sampler indirect_effect Indirrect effedt summary_gibbs Produce a summary table of the output from gibbs_wrapper. total_effect Total effect traceplot Produce traceplot for the specified parameter zero.centered.em Perform EM Algorithm on Pleiotropy
~~ An overview of how to use the package, including the most important functions ~~
Jingshu Wang [aut], Ethan Lewis [aut], Zixuan Wu [aut, cre]
Maintainer: Zixuan Wu <[email protected]>
~~ Literature or other references for background information ~~
# simple examples of the most important functions ~~
# simple examples of the most important functions ~~
Bayes approach for MR Mediation model.
BayesMediation( Gamma_hat, Sd_hat, init = "Random", iter = 6000, warmup = 3000, second = F, inv = FALSE, cor = NULL, Raw = T, total = F, indirect = F )
BayesMediation( Gamma_hat, Sd_hat, init = "Random", iter = 6000, warmup = 3000, second = F, inv = FALSE, cor = NULL, Raw = T, total = F, indirect = F )
Gamma_hat |
The estimated exposure and outcome effects gamma_hat |
Sd_hat |
The standarded errors of gamma_hat |
init |
Starting value for gibbs sampler. Either "Random" or "EM" |
iter |
The number of iterations for gibbs sampler |
warmup |
The nnumber of warmup periods |
second |
Whether to run the second stage. Default is False. |
inv |
When inv = False, we are estiming B in Gamma = (I + B) alpha; inv = True, we are estimating B in Gamma = B Gamma + alpha. |
cor |
The correlation matrix |
Raw |
Whether to include the unprocessed raw outputs. Default is F |
total |
Whether to include the total effects. Default is F |
indirect |
Whether to include the indirect effects. Default is F. |
A list with elements
summary_first |
|
summary_second |
|
total_effect_first |
computed by first stage (included if total = T)
total_effect_second |
computed by second stage (included if total = T and second = T)
indirect_effect_first |
computed by first stage (included if indirect = T)
indirect_effect_second |
computed by second stage (included if indirect = T and second = T)
raw_first |
|
raw_second |
Model is that Y = (I+B)A + noise
gibbs_sampler( Y, Sd_hat, N, B, sigma, sigma1, sigma0, p, A, Z, alpha_B, beta_B, alpha_0, alpha_1, beta_0, beta_1, a, b )
gibbs_sampler( Y, Sd_hat, N, B, sigma, sigma1, sigma0, p, A, Z, alpha_B, beta_B, alpha_0, alpha_1, beta_0, beta_1, a, b )
Y |
KxP arma::matrix of GWAS marginal associations |
Sd_hat |
KxP arma::matrix of GWAS std errors |
N |
number of samples to obtain |
B |
initial value of B arma::matrix |
sigma |
Initial value of prior std deviation for values of B |
sigma1 |
K-arma::vector of Initial values of prior slab SDs for each trait's pleiotropy |
sigma0 |
K-arma::vector of Initial values of prior splike SDs for each trait's pleiotropy |
p |
K-arma::vector of initial values for p, which is slab probability for mixture |
A |
KxP arma::matrix of initial values for A (ignored) |
Z |
KxP arma::matrix of initial values for Z (ignored), which is latent varaible indicating if A[i,j] comes from slab |
alpha_B |
Shape parameter of InvGamma prior for sigma (for B) |
beta_B |
Scale parameter of InvGamma prior for sigma (for B) |
alpha_0 |
K-arma::vector Shape parameter of InvGamma prior for sigma0 (Spike) |
alpha_1 |
K-arma::vector Shape parameter of InvGamma prior for sigma0 (Slab) |
beta_0 |
K-arma::vector Scale parameter of InvGamma prior for sigma0 (Spike) |
beta_1 |
K-arma::vector Scale parameter of InvGamma prior for sigma0 (Slab) |
a |
K-arma::vector First parameter of beta prior for p |
b |
K-arma::vector Second parameter of beta prior for p |
Model is that Y = (I+B)A + noise
gibbs_sampler_with_corr( Y, Sd_hat, trait_corr, N, B, sigma, sigma1, sigma0, p, A, Z, alpha_B, beta_B, alpha_0, alpha_1, beta_0, beta_1, a, b, Lambda3, Lambda_inv3 )
gibbs_sampler_with_corr( Y, Sd_hat, trait_corr, N, B, sigma, sigma1, sigma0, p, A, Z, alpha_B, beta_B, alpha_0, alpha_1, beta_0, beta_1, a, b, Lambda3, Lambda_inv3 )
Y |
KxP arma::matrix of GWAS marginal associations |
Sd_hat |
KxP arma::matrix of GWAS std errors |
trait_corr |
KxK arma::matrix of correlation of noises. |
N |
number of samples to obtain |
B |
initial value of B arma::matrix |
sigma |
Initial value of prior std deviation for values of B |
sigma1 |
K-arma::vector of Initial values of prior slab SDs for each trait's pleiotropy |
sigma0 |
K-arma::vector of Initial values of prior splike SDs for each trait's pleiotropy |
p |
K-arma::vector of initial values for p, which is slab probability for mixture |
A |
KxP arma::matrix of initial values for A (ignored) |
Z |
KxP arma::matrix of initial values for Z (ignored), which is latent varaible indicating if A[i,j] comes from slab |
alpha_B |
Shape parameter of InvGamma prior for sigma (for B) |
beta_B |
Scale parameter of InvGamma prior for sigma (for B) |
alpha_0 |
K-arma::vector Shape parameter of InvGamma prior for sigma0 (Spike) |
alpha_1 |
K-arma::vector Shape parameter of InvGamma prior for sigma0 (Slab) |
beta_0 |
K-arma::vector Scale parameter of InvGamma prior for sigma0 (Spike) |
beta_1 |
K-arma::vector Scale parameter of InvGamma prior for sigma0 (Slab) |
a |
K-arma::vector First parameter of beta prior for p |
b |
K-arma::vector Second parameter of beta prior for p |
Lambda3 |
Precomputed covariance matrix |
Lambda_inv3 |
Precomputed inverse covariance matrix |
Given the observed effect and standard error, run gibbs sampler to draw samples from the posterior density
gibbs_wrapper( N, warmup, chains = 4, Gamma_hat, Sd_hat, sigma, sigma_1, sigma_0, p, parallel = TRUE, init = "Random", ratio = 10, cor_mat = NULL, Lambda = NULL, Lambda_inv = NULL )
gibbs_wrapper( N, warmup, chains = 4, Gamma_hat, Sd_hat, sigma, sigma_1, sigma_0, p, parallel = TRUE, init = "Random", ratio = 10, cor_mat = NULL, Lambda = NULL, Lambda_inv = NULL )
N |
Number of total iterations |
warmup |
Number of warm-up iterations. |
chains |
Number of Chains. |
Gamma_hat |
The observed effects |
Sd_hat |
The standard deviation of Gamma_hat |
sigma |
The prior mean for sigma |
sigma_1 |
The prior mean for sigma_1 |
sigma_0 |
The prior mean for sigma_0 |
p |
The prior mean for p |
parallel |
Indicating whether to parallelly run all the chains. Default is True. |
init |
Method of Initialization. Must be one of "EM" or "Random". Default is "Random" |
ratio |
The ratio of initial sigma1 and sigma0 when the initialization method is "Random". Default is 10. |
cor_mat |
The correlation matrix for noise. Default is null (no correlation) |
Lambda |
The block diagonal matrix such that each block is the covariance matrix of the noise for a SNP. Default is NULL (not provided) |
Lambda_inv |
The block diagonal matrix such that each block is the inverse of covariance matrix of the noise for a SNP. Default is NULL (not provided). |
A list of which the elements are outputs from each chain. Each of these outputs is a list with attributes
B |
|
p |
|
sigma1 |
|
sigma0 |
|
pi |
|
sigma |
Estimate the indirrect effect of an exposure on the outcome
indirect_effect(results, K, warmup = 3000)
indirect_effect(results, K, warmup = 3000)
results |
results from gibbs_wrapper |
K |
number of phenotypes |
warump |
The length of warmup period. Default is 3000 |
A matrix of indirect effect and its quantiles.
Produce a summary table of the output from gibbs_wrapper.
summary_gibbs(result, pars, K, T = 1000, inv = FALSE)
summary_gibbs(result, pars, K, T = 1000, inv = FALSE)
result |
The output of gibbs_wrapper or gibbs_wrapper_cor |
pars |
A vector of parameters to be included in the summary table |
K |
The number of mediation layers |
T |
The warmup period. Default is 1000. |
inv |
When inv is TRUE, the function shows summary statistics for B in Gamma = B Gamma + alpha, otherwise it shows summary statistics for B in Gamma = (I + B) alpha. Default is False |
A table where each row corresponds to a parameter. It has columns:
mean |
|
variance |
|
sd |
|
2.5% |
|
50% |
|
97.5% |
|
ESS |
|
R_hat |
of convergence
Estimate the total effect of an exposure on the outcome
total_effect(results, K, warmup = 3000)
total_effect(results, K, warmup = 3000)
results |
results from gibbs_wrapper |
K |
number of phenotypes |
warump |
The length of warmup period. Default is 3000 |
A matrix of total effect and its quantiles.
Produce traceplot for the specified parameter
traceplot(results, par, ind, chains = -1, ylim = NA, T = 1000)
traceplot(results, par, ind, chains = -1, ylim = NA, T = 1000)
results |
The output of gibbs_wrapper. |
ind |
The index of the parameter. For "B" it is a two-vector. For "sigma1", "sigma0" and "pi" it is a single number. For "sigma" ind is ignored. |
chains |
The indices of chains to be included in the plot. Default is -1, which uses all the chains. |
ylim |
The range of y-axis in the final plot |
T |
The number of warmup period. |
pars |
A parameter to be ploted. Must be one of "B", "sigma", "sigma1", "sigma0" and "pi". |
A traceplot of a scalar parameter after warmup-period
Fit a two-component zero-mean Gaussian mixture on a sequence of observed values
zero.centered.em( values, std.errors, initial_slab_prob = 0.05, initial_sigma1_squared = 0.1, initial_sigma2_squared = 1e-04, iters = 100, optimizer = "Brent", show_outputs = FALSE )
zero.centered.em( values, std.errors, initial_slab_prob = 0.05, initial_sigma1_squared = 0.1, initial_sigma2_squared = 1e-04, iters = 100, optimizer = "Brent", show_outputs = FALSE )
values |
A vector of observations. |
initial_slab_prob |
The initial value for the proportion of slab (the Gaussian component with higher variance). Default is .05. |
initial_sigma1_squared |
The initial value for the variance of the slab component. Default is .1. |
initial_sigma2_squared |
The initial value for the variance of the spike component. Default is .0001 |
iters |
The number of iterations of EM algorithm. Default is 100 |
optimizer |
The method used in Maximization Step. Must be one of "Brent", "Nelder-Mead" and "L-BFGS-B". Default is "Brent". |
show_outputs |
Whether to included a plot of the fitted density and the smoothed data density. Default is FALSE. |
std.error |
The standard error of noise of observations. |
A list of elements
S1 |
|
S2 |
|
Pi |