如何获得每个基因的Cox p值?

时间:2016-04-18 18:07:14

标签: r survival-analysis cox-regression

如果运行以下代码,您将拥有一个数据框real.dat,其中包含1063个样本,用于20531个基因。还有2个名为timeevent的额外列,其中time为生存时间,eventdeath 1和{0 1}}如果是censored

lung.dat <- read.table("genomicMatrix_lung")
lung.clin.dat <- read.delim("clinical_data_lung")

# For clinical data, get only rows which do not have NA in column "X_EVENT"
lung.no.na.dat <- lung.clin.dat[!is.na(lung.clin.dat$X_EVENT), ]

# Getting the transpose of main lung cancer data
ge <- t(lung.dat)
# Getting a vector of all the id's in the clinical data frame without any 'NA' values
keep <- lung.no.na.dat$sampleID

# getting only the samples(persons) for which we have a value rather than 'NA' values
real.dat <- ge[ge[, 1] %in% keep, ]

# adding the 2 columns from clinical data to gene expression data
keep_again <- real.dat[, 1]
temp_df <- lung.no.na.dat[lung.no.na.dat$sampleID %in% keep_again, ]

# naming the columns into our gene expression data
col_names <- ge[1, ]
colnames(real.dat) <- col_names

dd <- temp_df[, c('X_TIME_TO_EVENT', 'X_EVENT')]
real.dat <- cbind(real.dat, dd)

# renaming the 2 new added columns
colnames(real.dat)[colnames(real.dat) == 'X_TIME_TO_EVENT'] <- 'time'
colnames(real.dat)[colnames(real.dat) == 'X_EVENT'] <- 'event'

我想获得上述数据框中每个基因的单变量Cox回归p值。我怎么能得到这个?

您可以从here下载数据。

Edit:很抱歉没有说清楚。我已经尝试使用coxph库中的survival函数来获取它。但即使对于一个基因,它也会显示以下错误 -

> coxph(Surv(time, event) ~ HIF3A, real.dat) Error in fitter(X, Y, strats, offset, init, control, weights = weights, : NA/NaN/Inf in foreign function call (arg 6) In addition: Warning message: In fitter(X, Y, strats, offset, init, control, weights = weights, : Ran out of iterations and did not converge

这就是为什么我没有提供一个较小的可重复的例子。

1 个答案:

答案 0 :(得分:1)

你真的会对20531个基因的每个基因进行单变量回归吗?

疯狂地猜测数据的结构(根据帮助中的示例创建一个虚拟集),并猜测你尝试用以下玩具示例做什么......

library("survival")
?coxph ## to see the examples
## create dummy data
test <- list(time=c(4,3,1,1,2,2,3), 
          event=c(1,1,1,0,1,1,0), 
          gene1=c(0,2,1,1,1,0,0), 
          gene2=c(0,0,0,0,1,1,1))
## Cox PH regression
coxph(Surv(time, event) ~ gene1, test) 
coxph(Surv(time, event) ~ gene2, test)

您可能希望使用以下内容来获取CI和更多信息。

summary(coxph(...)) 

希望该代码具有足够的可重现性,以帮助您澄清问题