[R] p-values from coxph?

David Winsemius dwinsemius at comcast.net
Fri Oct 15 17:25:42 CEST 2010


On Oct 15, 2010, at 9:21 AM, Öhagen Patrik wrote:

>
> Dear List,
>
> I each iteration of a simulation study, I would like to save the p- 
> value generated by "coxph". I fail to see how to adress the p-value.  
> Do I have to calculate it myself from the Wald Test statistic?
>
No. And the most important reason is that would not give you the same  
value as is print()-ed by coxph().

If you ask for the the str(print(coxph(...)) you get NULL (after the  
side-effect of prinitng. The print function only produces side- 
effects. On the other hand you can use the summary function and it  
gives you a richer set of output.  Using the first example on the help  
page for coxph:

str(summary(coxph(Surv(time, status) ~ x + strata(sex), test1)))
List of 12
  $ call        : language coxph(formula = Surv(time, status) ~ x +  
strata(sex), data = test1)
  $ fail        : NULL
  $ na.action   : NULL
  $ n           : int 7
  $ loglik      : num [1:2] -3.87 -3.33
  $ coefficients: num [1, 1:5] 0.802 2.231 0.822 0.976 0.329
   ..- attr(*, "dimnames")=List of 2
   .. ..$ : chr "x"
   .. ..$ : chr [1:5] "coef" "exp(coef)" "se(coef)" "z" ...
  $ conf.int    : num [1, 1:4] 2.231 0.448 0.445 11.18
   ..- attr(*, "dimnames")=List of 2
   .. ..$ : chr "x"
   .. ..$ : chr [1:4] "exp(coef)" "exp(-coef)" "lower .95" "upper .95"
  $ logtest     : Named num [1:3] 1.087 1 0.297
   ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
  $ sctest      : Named num [1:3] 1.051 1 0.305
   ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
  $ rsq         : Named num [1:2] 0.144 0.669
   ..- attr(*, "names")= chr [1:2] "rsq" "maxrsq"
  $ waldtest    : Named num [1:3] 0.95 1 0.329
   ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue"
  $ used.robust : logi FALSE

So the fifth element of  coefficients leaf of the list structure has  
the same "p-value" as that print()-ed.

Try:

 > summary(fit)$coefficients[5]
[1] 0.3292583

(It does seem to me that the name for that leaf of the fit object is  
not particularly in accord with what I would have considered  
"coefficients"., but I am really in no solid position to criticize  
Terry Therneau to whom we all owe a great deal of gratitude.)


-- 
David.


More information about the R-help mailing list