
发布日期:2025-05-21 11:09 点击次数:140
大家好,我是邓飞。
前几天一直学习孟德尔随机化的理论知识,写了几篇博客,迷迷糊糊感觉入门了,今天跑代码试了试,看着结果和图表,感觉理解更深入了。果然,看书百遍,不如一练,今天分享一下实操代码。
前几天的博客:
孟德尔随机化的术语理解
孟德尔随机化:工具变量三大假设
从一篇孟德尔随机化文章看MR常见结果形式
示例数据使用官网的数据,进行了一点补充,对结果进行了可视化。(https://mrcieu.github.io/TwoSampleMR/articles/introduction.html)
整个步骤:
图片
步骤1:提取暴露数据的GWAS
图片
> ## 1, 安装TwoSampleMR,如果已安装,可以忽略> > # library(remotes)> # install_github("MRCIEU/TwoSampleMR")> > ## 2, 载入TwoSampleMR包> library(TwoSampleMR)> > ## 3,从数据库中提取暴露的GWAS summary数据> exposure_dat = extract_instruments("ieu-a-2")> dim(exposure_dat)[1] 79 15
共有79行15列的暴露数据结果。
步骤2:提取结局数据的GWAS
图片
> ## 4,从数据库中提取结局变量的的GWAS summary数据,SNP用暴露数据的结果> # Get effects of instruments on outcome> outcome_dat = extract_outcome_data(snps=exposure_dat$SNP, outcomes = "ieu-a-7")Extracting data for 79 SNP(s) from 1 GWAS(s)> dim(outcome_dat)[1] 79 16
共79行15列的结局数据,注意,这里直接使用暴露数据质控后的SNP,提取结局数据得到的结果,所以位点数是一样的。
步骤3:合并暴露数据和结局数据
图片
> ## 5,将暴露数据和结局数据合并> # Harmonise the exposure and outcome data> dat = harmonise_data(exposure_dat, outcome_dat)Harmonising Body mass index
Powered by 飞艇高手计划稳定回血技巧 @2013-2022 RSS地图 HTML地图