extract p value from coxph

Hi!
I try extract p-values from coxph model. My covarianse as a factor. That I get when run summary(fit):

Call:
coxph(formula = Surv(OS, OS_status) ~ PS_at_IO, data = analysis)

  n= 453, number of events= 280 

             coef exp(coef) se(coef)     z Pr(>|z|)    
PS_at_IO1  0.5699    1.7680   0.1606 3.549 0.000387 ***
PS_at_IO2  1.1077    3.0273   0.1751 6.327  2.5e-10 ***
PS_at_IO3  1.8515    6.3692   0.2137 8.666  < 2e-16 ***
PS_at_IO4  3.4599   31.8147   0.5350 6.467  1.0e-10 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

          exp(coef) exp(-coef) lower .95 upper .95
PS_at_IO1     1.768    0.56560     1.291     2.422
PS_at_IO2     3.027    0.33033     2.148     4.266
PS_at_IO3     6.369    0.15700     4.190     9.682
PS_at_IO4    31.815    0.03143    11.148    90.794

Concordance= 0.691  (se = 0.017 )
Likelihood ratio test= 93.18  on 4 df,   p=<2e-16
Wald test            = 111.2  on 4 df,   p=<2e-16
Score (logrank) test = 146.2  on 4 df,   p=<2e-16

And that I get when try extract only p-value (I google sulution):

summary(fit_cox)$coefficients[5]
[1] 1.768025

I really don't understand why this. Is it problem that my covariance as.factor?

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. Here, without the analysis object, it's necessary to turn to the example in the help(coxph) page.

Unfortunately, there are many functions by that name, so I'll assume the one in the survival package.

This version returns a proportional hazards regression model object

to represent a fitted proportional hazards model

If you give your model as an argument to str() you will indeed see that it contains no slot for p-value, which makes sense, since it is used to perform tests, not to report them.

Then there's something I don't understand. If I use Age as my covarian, then everything works.
and here output of summary(fit_cox):

Call:
coxph(formula = Surv(OS, OS_status) ~ Age, data = analysis)

  n= 453, number of events= 280 

        coef exp(coef) se(coef)     z
Age 0.008095  1.008128 0.006263 1.293
    Pr(>|z|)
Age    0.196

    exp(coef) exp(-coef) lower .95
Age     1.008     0.9919    0.9958
    upper .95
Age     1.021

Concordance= 0.508  (se = 0.02 )
Likelihood ratio test= 1.68  on 1 df,   p=0.2
Wald test            = 1.67  on 1 df,   p=0.2
Score (logrank) test = 1.67  on 1 df,   p=0.2

and here output for:

summary(fit_cox)$coefficients[5]
[1] 0.1961823

that exacttly p-value what i search.
here output str(summary(fit_cox):

str(summary(fit_cox))
List of 14
 $ call        : language coxph(formula = Surv(OS, OS_status) ~ Age, data = analysis)
 $ fail        : NULL
 $ na.action   : NULL
 $ n           : int 453
 $ loglik      : num [1:2] -1515 -1514
 $ nevent      : num 280
 $ coefficients: num [1, 1:5] 0.00809 1.00813 0.00626 1.29251 0.19618
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr "Age"
  .. ..$ : chr [1:5] "coef" "exp(coef)" "se(coef)" "z" ...
 $ conf.int    : num [1, 1:4] 1.008 0.992 0.996 1.021
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr "Age"
  .. ..$ : chr [1:4] "exp(coef)" "exp(-coef)" "lower .95" "upper .95"
 $ logtest     : Named num [1:3] 1.679 1 0.195
  ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
 $ sctest      : Named num [1:3] 1.67 1 0.196
  ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
 $ rsq         : Named num [1:2] 0.0037 0.9988
  ..- attr(*, "names")= chr [1:2] "rsq" "maxrsq"
 $ waldtest    : Named num [1:3] 1.67 1 0.196
  ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
 $ used.robust : logi FALSE
 $ concordance : Named num [1:2] 0.5076 0.0198
  ..- attr(*, "names")= chr [1:2] "C" "se(C)"
 - attr(*, "class")= chr "summary.coxph"

What happens when you supply stata arguments?

For example if I use covariance PS_at_IO - as factor with 4 levels. so str(summary(cox_fit):

List of 14
 $ call        : language coxph(formula = Surv(OS, OS_status) ~ PS_at_IO, data = analysis)
 $ fail        : NULL
 $ na.action   : NULL
 $ n           : int 453
 $ loglik      : num [1:2] -1515 -1468
 $ nevent      : num 280
 $ coefficients: num [1:4, 1:5] 0.57 1.11 1.85 3.46 1.77 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "PS_at_IO1" "PS_at_IO2" "PS_at_IO3" "PS_at_IO4"
  .. ..$ : chr [1:5] "coef" "exp(coef)" "se(coef)" "z" ...
 $ conf.int    : num [1:4, 1:4] 1.768 3.027 6.369 31.815 0.566 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "PS_at_IO1" "PS_at_IO2" "PS_at_IO3" "PS_at_IO4"
  .. ..$ : chr [1:4] "exp(coef)" "exp(-coef)" "lower .95" "upper .95"
 $ logtest     : Named num [1:3] 9.32e+01 4.00 2.78e-19
  ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
 $ sctest      : Named num [1:3] 1.46e+02 4.00 1.33e-30
  ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
 $ rsq         : Named num [1:2] 0.186 0.999
  ..- attr(*, "names")= chr [1:2] "rsq" "maxrsq"
 $ waldtest    : Named num [1:3] 1.11e+02 4.00 3.99e-23
  ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
 $ used.robust : logi FALSE
 $ concordance : Named num [1:2] 0.6912 0.0168
  ..- attr(*, "names")= chr [1:2] "C" "se(C)"
 - attr(*, "class")= chr "summary.coxph"

I cant find p-value here.

library(survival)
# Fit a stratified model 
coxph(Surv(time, status) ~ x + strata(sex), test1) # <= strata argument
#> Error in terms.formula(formula, specials = ss, data = data): object 'test1' not found
# Create a simple data set for a time-dependent model 
test2 <- list(start=c(1,2,5,2,1,7,3,4,8,8), 
              stop=c(2,3,6,7,8,9,9,9,14,17), 
              event=c(1,1,1,1,1,1,1,0,0,0), 
              x=c(1,0,0,1,0,1,1,1,0,0)) 
fit <- summary(coxph(Surv(start, stop, event) ~ x, test2)) 
fit$coefficients
#>          coef exp(coef)  se(coef)           z  Pr(>|z|)
#> x -0.02110521 0.9791159 0.7951769 -0.02654153 0.9788254

Created on 2020-03-24 by the reprex package (v0.3.0)

Thank you. with strata its work. One more queastion how I decide what best strata ? my different cohorts for example. I don't really get the point strata.
there example that work with strata:

Call:
coxph(formula = Surv(OS, OS_status) ~ PS_at_IO + strata(Cohort), 
    data = analysis)

  n= 453, number of events= 280 

             coef exp(coef) se(coef)     z Pr(>|z|)    
PS_at_IO1  0.5620    1.7543   0.1643 3.421 0.000625 ***
PS_at_IO2  1.1239    3.0767   0.1780 6.315 2.70e-10 ***
PS_at_IO3  1.8304    6.2362   0.2169 8.439  < 2e-16 ***
PS_at_IO4  3.3194   27.6447   0.5440 6.102 1.05e-09 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

          exp(coef) exp(-coef) lower .95 upper .95
PS_at_IO1     1.754    0.57004     1.271     2.421
PS_at_IO2     3.077    0.32502     2.171     4.361
PS_at_IO3     6.236    0.16035     4.077     9.540
PS_at_IO4    27.645    0.03617     9.519    80.286

Concordance= 0.694  (se = 0.017 )
Likelihood ratio test= 89.65  on 4 df,   p=<2e-16
Wald test            = 104.5  on 4 df,   p=<2e-16
Score (logrank) test = 132.3  on 4 df,   p=<2e-16

and:

summary(fit_cox)$coefficients
               coef exp(coef)  se(coef)        z     Pr(>|z|)
PS_at_IO1 0.5620439  1.754254 0.1643071 3.420692 6.246200e-04
PS_at_IO2 1.1238590  3.076704 0.1779639 6.315095 2.699961e-10
PS_at_IO3 1.8303778  6.236242 0.2169004 8.438795 3.206247e-17
PS_at_IO4 3.3194356 27.644743 0.5439696 6.102244 1.045894e-09

once again thak you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.