Reputation: 188
I need to extract the p
attribute of a specific row in the output of cox.zph
function in R.
To put you in question, I describe my problem as follows, step by step with an example:
require('survival')
# I create the simplest test data set
test1 <- list(time=c(4,3,1,1,2,2,3),
status=c(1,1,1,0,1,1,0),
x=c(0,2,1,1,1,0,0),
sex=c(0,0,0,0,1,1,1))
# Fit a stratified model
coxmodel <- coxph(Surv(time, status) ~ x + strata(sex), test1)
And then, I use cox.zph
function:
zph <- cox.zph(coxmodel)
With the following output:
rho chisq p
x 0.354 0.322 0.57
I tried to get p
attribute value (in this case, 0.57) by using attributes(zph)
but p
doesn't appear in order to do something like zph$p
. I also used plyr
package with no results.
Does anyone could help me? Thanks.
Upvotes: 3
Views: 1160
Reputation: 17120
Here it is:
zph$table[ , "p" ]
The you can access the members of the zph object using $
, since it is a list:
names( zph )
# returns:
# [1] "table" "x" "y" "var" "call" "transform"
Then look up zph$table
and presto.
In R, usually the different "slots" of an object are accessible through $
(S3 OO framework) or @
(S4 OO framework).
Upvotes: 4