1. 工具变量
install.packages("remotes")
remotes::install_github("MRCIEU/TwoSampleMR")##To update the package just run the command again
install.packages("readxl")
读取本地文件
- 方法1:先改变量名,然后
format_data()
读取自己整理好的工具变量文件,命名如下图。注意,命名区分大小写,不正确则无法读取
##name:SNP beta se effect_allele eaf exposure chr position gene pval samplesize mr_keep
HcyIV <- as.data.frame(read_excel("IV_Hcy.xlsx"))
library(TwoSampleMR)
Hcy_exp_dat <- format_data(HcyIV, type="exposure")
- 方法2:直接用
read_exposure_data()
读,然后code改。尽可能提供多的信息,方便后期画图
HcyIV.2 <- read_exposure_data(
filename = "IV_Hcy2.csv",
sep = ",",
snp_col = "SNP",
beta_col = "beta",
se_col = "se",
effect_allele_col = "effect_allele",
#other_allele_col = "a2",
eaf_col = "eaf",
pval_col = "pval",
#units_col = "Units",
#gene_col = "Gene",
samplesize_col = "samplesize"
)
- 最后改好自己的暴露名
Hcy_exp_dat$exposure <- "Homocysteine"
工具变量必须为独立变量。根据参考文献选择ref人群和r2