R语言实现计算MR工具变量F-staistics(1)

#F-statistics
#Basic analysis
#导入包
library(TwoSampleMR)
library(MRPRESSO)
#导入暴露变量数据:aspirin----ukb-b-8755
aaa<- extract_instruments(outcomes='ukb-b-8755',
                          clump=TRUE, p1 = 5e-08,
                          r2=0.001,kb=10000,access_token=NULL)
#Method 1 : Convert eaf to maf
aaa$MAF = ifelse(aaa$eaf.exposure < 0.5, 
                 aaa$eaf.exposure,
                 1-aaa$eaf.exposure)
Ff<-function(data){
  maf<-ifelse(data$eaf.exposure < 0.5, 
              data$eaf.exposure,
              1-data$eaf.exposure)
  n<-data$samplesize.exposure
  eaf<-data$eaf.exposure
  beta<-data$beta.exposure
  se<-data$se.exposure
  #The below two methods are all right
  #rr<-(2*(beta^2)*eaf*(1-eaf)) /(2*(beta^2)*eaf* (1-eaf) +2*n*eaf*(1-eaf)*se^2)
  rr<-beta^2/(beta^2+se^2*(data$samplesize.exposure-2))
  ff<-((n-2)*rr)/(1-rr)
  mean<-mean(ff)
  li<-list(r2=rr,
           fs=ff,
           fm=mean)
  print(mean)
  print("if fm=<10, please pay attention to weak instrument bias")
  return(li)
}
a<-Ff(data=aaa)

你可能感兴趣的:(GWAS,r语言)