This package implements the debiased mixture inverse weighting method in the paper: A flexible framework for robust and efficient Mendelian randomization with debiasing.
You can install the development version of dmIVW like so:
#install.packages(devtools)
devtools::install_github("XXX/MRdmIVW") # Will be released later.Or, if you have downloaded the package file (MRdmIVW.zip) locally, you can install it using the devtools::install_local() function as follows:
#install.packages(devtools)
devtools::install_local("path/to/MRdmIVW.zip")#install.packages(devtools)
install.packages("MendelianRandomization")
install_github("qingyuanzhao/mr.raps")We use the bmi.bmi data in the R package mr.raps as an example.
library(MendelianRandomization)
# We use bmi.bmi data in mr.raps as an example
library(mr.raps)
library(MRdmIVW)
set.seed(0)
data(bmi.bmi)
# To save time, we use a subset of SNPs as IVs, one can take all SNPs.
ind = which(bmi.bmi$pval.selection<1e-8)To begin with, we need to transform the data into MRInput Class of R package of MendelianRandomization.
mr.bmi.bmi = mr_input(bx=bmi.bmi$beta.exposure[ind],by=bmi.bmi$beta.outcome[ind],
bxse=bmi.bmi$se.exposure[ind],byse=bmi.bmi$se.exposure[ind])Then, we can perform the model selection version of dmIVW method. We set the maximum number of groups as 2. The result can be printed and visualized.
##=============================================================
## Model Selection
res_msel = mr_dmIVW(mr.bmi.bmi,Kmax=2)
print(res_msel)
plot_mr_dmIVW(res_msel)To consider the model-averaging version of the dmIVW method, the number of submodels to be averaged (n.topModel) can be set to a value greater than 1 (e.g., 5).
##=============================================================
## Model Average
res_mavr = mr_dmIVW(mr.bmi.bmi,Kmax=2,n.topModel = 5)
print(res_mavr)
plot_mr_dmIVW(res_mavr)We may also want to specify submodel in advance. We can use gen_m_Type to generate the model (see ?gen_m_Type for details). We can then perform dmIVW for this particular submodel.
##=============================================================
## Specifical Model
m_Type = gen_m_Type(K=2,fix.balance= T,fix.direction=T,is.correlated = T)
res_2grp = mr_dmIVW(mr.bmi.bmi,m_Type = m_Type)
print(res_2grp)
plot_mr_dmIVW(res_2grp)