Question: Obtaining P Values from Cox Regression in R
gravatar for menon_ankita
4 weeks ago by
menon_ankita20 wrote:


I am a student conducting a survival analysis in R. I am using 6,000 genes from 249 patients each, and am testing each gene separately by putting them in an individual Cox regression model. Here is the code that I have written in order to be able to test them all at the same time instead of creating 6,000 different models (for reference, EFST is the event free survival time and Status is the vital state after the first event):

dataOne <- read.delim("/Users/menon/OneDrive/Desktop/csrsef files/FirstSplitDataFrame.txt")
myFinalData <- dataOne[, -1]
EFST <- myFinalData[ , c("EFST")] 
Status <- myFinalData[, c("Status")]
formulas <- sapply(names(myFinalData)[3:ncol(myFinalData)], function(x) as.formula(paste
('Surv(EFST, Status) ~ ',x)))
models <- lapply(formulas, function(x) coxph(x, data=myFinalData))
res <- lapply(models, function(x) return(cbind(HR=exp(coef(x)), exp(confint(x)))))

This code works, however this only gives me the hazard ratios and the confidence intervals, whereas I would like the p-values as well. I have tried multiple different things to include the p-value, but to no avail.

Additionally; if I wanted to add other factors (for ex., factor(age)), how would I modify this code in order to do that? I am not able to make it a multivariate regression model whenever I try.

Any help would be extremely appreciated!

Thank you,


ADD COMMENTlink modified 4 weeks ago by Kevin Blighe56k • written 4 weeks ago by menon_ankita20
gravatar for Kevin Blighe
4 weeks ago by
Kevin Blighe56k
Kevin Blighe56k wrote:

The p-values can be obtained via the summary() function applied to your model.

The summary function will then have the following values of interest

  • coefficients, coefficient p-values, SEs, beta coefficients, etc.
  • logtest, likelihood ratio test p-value
  • sctest, Score / logRank test p-value
  • waldtest, Wald test p-value


ADD COMMENTlink written 4 weeks ago by Kevin Blighe56k

Hello Dr. Blighe, Thank you for the response. That is what I initially thought as well, but entering summary(res) gives me an output of something like this:

Length Class  Mode   
AADACL3     3      -none- numeric
AADACL4     3      -none- numeric
ACADM       3      -none- numeric
ACAP3       3      -none- numeric


ADD REPLYlink modified 4 weeks ago by Kevin Blighe56k • written 4 weeks ago by menon_ankita20

Hello Professor Menon, that is due to the fact that your res object is not produced directly from coxph(). You will have to apply summary() to your models list object, most likely via another lapply function.

Something like I do in this code chunk from my package RegParallel:

ADD REPLYlink written 4 weeks ago by Kevin Blighe56k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1255 users visited in the last hour