How to extract values ​​from survif object

I created this model:

model <- survfit(Surv(time,status)~c$sex)
model

and output:

Call: survfit(formula = Surv(time, status) ~ c$sex)

             records n.max n.start events median 0.95LCL 0.95UCL
c$sex=female      15    15      15      8    720     517      NA
c$sex=male        28    28      28     23    234     145     712    

So, I want to extract a median for men and the same for women, but I have no idea how to do it. Here are my attempts to do this:

>model$median
NULL

>summary(model)$table[, "median"]
c$sex=female c$sex=male 
       720.0            234.5 

I want each of the values ​​to be one ("720" and "234.5"), can someone help me?

Thank you in advance

+4
source share
2 answers

This also works:

> library(survMisc)
> fit <- survfit(Surv(time, status) ~ x, data = aml)
> median(fit)
                median
x=Maintained        31
x=Nonmaintained     23

And without names (i.e. remove the structure data.frame):

> unname(unlist(median(fit)))
[1] 31 23

Well, if you also want a confidence interval (the default is "log"):

> median(fit, CI=TRUE)
                median lower upper
x=Maintained        31    13    NA
x=Nonmaintained     23     5    43
+3
source

You already have it. Everything that you see on the screen are attributes of a namesvector of length 2.

fit <- survfit(Surv(time, status) ~ x, data = aml)
summary(fit)$table
#                records n.max n.start events median 0.95LCL 0.95UCL
#x=Maintained         11    11      11      7     31      18      NA
#x=Nonmaintained      12    12      12     11     23       8      NA

#  Access first value like any other vector
summary(fit)$table[,'median'][1]
#x=Maintained 
#          31

unname()...

unname(summary(fit)$table[,'median'])
# [1] 31 23

unname() , ...

sum( summary(fit)$table[,'median'] )
[1] 54

(!), str()...

str(summary(fit)$table[,'median'])
# Named num [1:2] 31 23
# - attr(*, "names")= chr [1:2] "x=Maintained" "x=Nonmaintained"
+4

All Articles