Question

In my current work I often use survfit() to calculate the Kaplan-Meier estimate for survival data, and do the log-rank test using survdiff().

I would like to know how I could extract the formula and subset information from a survfit() call and input it directly into survdiff(). I usually use

survdiff(formula(survfit.object)) 

but this wont recognize any subset argument provided in my survfit call.

For example:

library(survival)

fail.time <- 12*rexp(100)
group <- factor(sample(1:3,100,replace=TRUE),1:3,c('a','b','c'))
fail.status <- rbinom(100,1,0.4)

srv<-survfit(Surv(fail.time,fail.status)~group,subset=group!="a")
survdiff(formula(srv))

which isn't what I want, rather I'd like

survdiff(formula(srv),subset=group!="a")

but I'm hoping to find a method which will allow me to not have to add the subset information again.

Thanks!

Was it helpful?

Solution

Most model fitting objects in R store the entire call:

survdiff(formula(srv),subset = srv$call$subset)

or just:

eval(srv$call)

which re-runs the original call in its entirety.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top