赞
踩
Error in ieugwasr::tophits(outcomes, pval = p1, clump = clump, r2 = r2, : 参数没有用(access_token = access_token)
- # 安装所需的包(如果尚未安装)
- # install.packages("remotes")
- # remotes::install_github("MRCIEU/TwoSampleMR")
-
- # 载入 TwoSampleMR 包
- library(TwoSampleMR)
-
- # 设置多个暴露因子和结果的数据ID
- exposureIDs <- c("ukb-b-9") # 暴露因子数据ID
- outcomeIDs <- c("ieu-a-1") # 结果数据ID
-
- # 设置工作目录
- setwd("E:\\zhuomian\\01多暴露因素对应多结局")
-
- # 创建一个空的数据框,用于存储所有结果
- finalResults <- data.frame()
-
- # 循环处理每个暴露因子
- for (exposureID in exposureIDs) {
- # 循环处理每个结果
- for (outcomeID in outcomeIDs) {
- # 提取暴露因子数据 p1数值可调整
- exposure_dat <- extract_instruments(exposureID, p1 = 1e-6, clump = TRUE)
-
- # 提取结果数据
- outcome_dat <- extract_outcome_data(snps = exposure_dat$SNP, outcomes = outcomeID)
-
- # 将暴露因子数据和结果数据进行协调
- dat <- harmonise_data(exposure_dat, outcome_dat)
-
- # 提取需要保留的数据用于后续分析
- outTab <- dat[dat$mr_keep == "TRUE", ]
- write.csv(outTab, file = paste0("table.SNP_", exposureID, "_", outcomeID, ".csv"), row.names = FALSE)
-
- # 进行 MR 分析
- mrResult <- mr(dat)
-
- # 选择特定的 MR 方法进行分析
- # 可以根据需要进行选择,以下为几种可选方法
- # mr_method_list()$obj
- mrResult <- mr(dat, method_list = c("mr_ivw", "mr_egger_regression", "mr_weighted_median", "mr_simple_mode", "mr_weighted_mode"))
-
- # 生成 Odds Ratios(OR)的表格
- mrTab <- generate_odds_ratios(mrResult)
- write.csv(mrTab, file = paste0("table.MRresult_", exposureID, "_", outcomeID, ".csv"), row.names = FALSE)
-
- # 进行异质性检验
- heterTab <- mr_heterogeneity(dat)
- write.csv(heterTab, file = paste0("table.heterogeneity_", exposureID, "_", outcomeID, ".csv"), row.names = FALSE)
-
- # 进行多重性检验
- pleioTab <- mr_pleiotropy_test(dat)
- write.csv(pleioTab, file = paste0("table.pleiotropy_", exposureID, "_", outcomeID, ".csv"), row.names = FALSE)
-
- # 将每次循环中生成的结果追加到总的结果数据框
- finalResults <- rbind(finalResults, cbind(exposureID = exposureID, outcomeID = outcomeID, mrTab))
- }
- }
-
- # 将 dev.off() 移到循环外部
- dev.off()
-
- # 将最终的结果写入一个总的CSV文件
- write.csv(finalResults, file = "finalResults.csv", row.names = FALSE)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。