p.value filtration from an lapply-function applied for the function coxph.

问题描述 投票:0回答:1

我正在运行566个基因的每个表达水平的生存分析。我是通过结合函数 coxph() 与函数 lapply,而且效果不错。现在,由于考虑的基因数量很多,我卡在了如何做P值过滤,以便只保留存活率显著的基因,即当P<0.05。

这就是虚数据。

 df1 = structure(list(ERLIN2 = structure(c(`TCGA-A1-A0SE-01` = 1L, `TCGA-A1-A0SH-01` = 1L, 
`TCGA-A1-A0SJ-01` = 1L), .Label = c("down", "up"), class = "factor"), 
    BRF2 = structure(c(`TCGA-A1-A0SE-01` = 2L, `TCGA-A1-A0SH-01` = 1L, 
    `TCGA-A1-A0SJ-01` = 2L), .Label = c("down", "up"), class = "factor"), 
    ZNF703 = structure(c(`TCGA-A1-A0SE-01` = 2L, `TCGA-A1-A0SH-01` = 1L, 
    `TCGA-A1-A0SJ-01` = 2L), .Label = c("down", "up"), class = "factor"), 
    time = c(43.4, 47.21, 13.67), event = c(0, 0, 0)), row.names = c("TCGA-A1-A0SE-01", 
"TCGA-A1-A0SH-01", "TCGA-A1-A0SJ-01"), class = "data.frame")

之后,为了得到结果, 请输入下面的代码行。

#library
if(!require(survival)) install.packages('survival')
library('survival')

#run survival analysis
df2=lapply(c("ERLIN2",    "BRF2",      "ZNF703"),

       function(x) {

         formula <- as.formula(paste('Surv(time,event)~',as.factor(x)))
         coxFit <- coxph(formula, data = df1)
         summary(coxFit)
       })

从这里开始,我试图做P值过滤,如下图所示。

for (i in 3){
    df2 = df2 %>% subset(df2[[i]]$logtest[3] < 0.05)
}

但是效率很低!任何帮助将是apriciated!

r survival-analysis cox-regression
1个回答
1
投票

如果你有兴趣通过任何变量(在你的情况下,logtest的p值)来子设置列表,我会建议你使用 rlist 包裹

library(rlist)

df3 <-  list.filter(df2, logtest[["pvalue"]] < 0.05)

这将根据指定的条件过滤列表。条件也可以是嵌套的。

© www.soinside.com 2019 - 2024. All rights reserved.