
rm(list=ls())
library(meta)
library(metafor)

## metagen
dat = read.csv("03 hallmarks.uniCox.csv")
dat$lnHR = log(dat$HR)
dat$lnL = log(dat$HR.95L)
dat$lnH = log(dat$HR.95H)
dat$seHR = (dat$lnH-dat$lnL)/(2*1.96)

result = data.frame()
var = unique(dat$id)
for (i in var) {
  dat1 = dplyr::filter(dat, dat$id %in% i)
  pfs=metagen(lnHR, seHR, sm="HR", data=dat1,
              studlab=paste(dat1$GSE, dat1$id, sep="."))
  result=rbind(result,
               cbind(id=i,
                     HR=round(2.718282^pfs$TE.fixed, 3),
                     HR.95L=round(2.718282^pfs$lower.fixed, 3),
                     HR.95H=round(2.718282^pfs$upper.fixed, 3),
                     pvalue=round(pfs$pval.fixed, 3)))
}

write.csv(result, "01 hallmarks.meta.csv", row.names = F)


