嗨,这应该让你开始。本质上,您可以遍历所有阈值,从所有 4 个数据帧中提取与每个阈值匹配的行到一个新数据帧中并运行您的元分析
library(metafor)
# Make some fake data resembling your own
df1 = data.frame(Set=rep("Base",8), Threshold=c(0.0001,0.001,0.05,seq(0.1,0.5,0.1)),
R2=runif(8,0.001,0.005),P=runif(8,0.001,1),Coefficient=runif(8,-0.1,0.2),
Standard.Error=runif(8,0.07,0.08),Num_SNP=sample(1:1000,8))
df2 = data.frame(Set=rep("Base",8), Threshold=c(0.0001,0.001,0.05,seq(0.1,0.5,0.1)),
R2=runif(8,0.001,0.005),P=runif(8,0.001,1),Coefficient=runif(8,-0.1,0.2),
Standard.Error=runif(8,0.07,0.08),Num_SNP=sample(1:1000,8))
df3 = data.frame(Set=rep("Base",8), Threshold=c(0.0001,0.001,0.05,seq(0.1,0.5,0.1)),
R2=runif(8,0.001,0.005),P=runif(8,0.001,1),Coefficient=runif(8,-0.1,0.2),
Standard.Error=runif(8,0.07,0.08),Num_SNP=sample(1:1000,8))
df4 = data.frame(Set=rep("Base",8), Threshold=c(0.0001,0.001,0.05,seq(0.1,0.5,0.1)),
R2=runif(8,0.001,0.005),P=runif(8,0.001,1),Coefficient=runif(8,-0.1,0.2),
Standard.Error=runif(8,0.07,0.08),Num_SNP=sample(1:1000,8))
Thresholds = unique(df1$Threshold)
Results <- NULL
for(i in 1:length(Thresholds)){
idf = rbind(df1[df1$Threshold==Thresholds[i],],
df2[df2$Threshold==Thresholds[i],],
df3[df3$Threshold==Thresholds[i],],
df4[df4$Threshold==Thresholds[i],])
i.meta <- rma.uni(yi=idf$Coefficient,sei=idf$Standard.Error, measure="GEN", method='FE',intercept=T,
weights=idf$Num_SNP)
Results <- rbind(Results, c(Threshold=Thresholds[i],beta=i.meta$beta,se=i.meta$se,
zval=i.meta$zval,pval=i.meta$pval,ci.lb=i.meta$ci.lb,
ci.ub=i.meta$ci.ub,QEp=i.meta$QEp))
}
Results <- data.frame(Results)
Results
应该给你:
Threshold beta se zval pval ci.lb ci.ub QEp
1 1e-04 -0.012079013 0.04715546 -0.2561530 0.79783270 -0.104502022 0.0803440 0.08700919
2 1e-03 0.068932388 0.04006086 1.7206917 0.08530678 -0.009585452 0.1474502 0.22294419
3 5e-02 0.050069503 0.04094881 1.2227340 0.22143020 -0.030188694 0.1303277 0.07342661
4 1e-01 0.102598016 0.04188183 2.4497022 0.01429744 0.020511132 0.1846849 0.07380669
5 2e-01 0.069482160 0.04722693 1.4712401 0.14122619 -0.023080930 0.1620452 0.95494364
6 3e-01 0.009793206 0.05098346 0.1920859 0.84767489 -0.090132542 0.1097190 0.12191340
7 4e-01 0.030432884 0.03967771 0.7670021 0.44308028 -0.047333994 0.1081998 0.86270334
8 5e-01 0.073511575 0.03997485 1.8389458 0.06592316 -0.004837683 0.1518608 0.12333557