# Remove confounding factors
# Basic analysis for MR
library(TwoSampleMR)
library(phenoscanner)
# Exposure data:aspirin----ukb-b-8755
aaa<- extract_instruments(outcomes='ukb-b-8755',
clump=TRUE,
r2=0.001,kb=10000,access_token=NULL)
# Using Phenoscanner to retrieve other traits related to IV
pcf<-function(ex,cf){
ot<-ex$SNP
outTab=data.frame()
for(i in 1:length(ot)){
#Extract confounders
confounder=phenoscanner(
snpquery = ot[i],
catalogue = "GWAS",
pvalue = 1e-05, #p-value for screening
proxies = "None",
r2 = 0.8, #r2 for screening
build = 37)#the genome build (options: 37, 38).
outTab=rbind(outTab, confounder$results)
}
# Load the important confounding factors
patterns <- paste(cf, collapse = "|")
pp<-grep(patterns,outTab$trait, ignore.case = TRUE)
cfs<-outTab[outTab$trait %in% outTab$trait[pp],]
abc<-ex[!(ex$SNP %in% cfs$snp),]
return(abc)
}
asd<-pcf(ex=aaa,cf=c("alcohol","Whole body fat mass"))
直接调用pcf函数即可快速去除混杂因素。ex为提取的暴露信息,cf为混杂因素名称。