Bernhard Reinhardt
2009-Feb-17 15:37 UTC
[R] Survival-Analysis: How to get numerical values from survfit (and not just a plot)?
Hi! I came across R just a few days ago since I was looking for a toolbox for cox-regression. I?ve read "Cox Proportional-Hazards Regression for Survival Data Appendix to An R and S-PLUS Companion to Applied Regression" from John Fox. As described therein plotting survival-functions works well (plot(survfit(model))). But I?d like to do some manipulation with the survival-functions before plotting them e.g. dividing one survival-function by another. survfit() only returns an object of the following structure n events median 0.9LCL 0.9UCL 55.000 55.000 1.033 0.696 1.637 Can you tell me how I can calculate a survival- or baseline-function out of these values and how I extract the values from the object? I?m sure the calculation is done by the corresponding plot-routine, but I couldn?t find that one either. Regards Bernhard
Arthur Allignol
2009-Feb-17 15:43 UTC
[R] Survival-Analysis: How to get numerical values from survfit (and not just a plot)?
Hi, See ?survfit.object if fit is the object you get using survfit, fit$surv will give you the survival probability. Best, arthur Bernhard Reinhardt wrote:> Hi! > > I came across R just a few days ago since I was looking for a toolbox > for cox-regression. > > I?ve read > "Cox Proportional-Hazards Regression for Survival Data > Appendix to An R and S-PLUS Companion to Applied Regression" from John Fox. > > As described therein plotting survival-functions works well > (plot(survfit(model))). But I?d like to do some manipulation with the > survival-functions before plotting them e.g. dividing one > survival-function by another. > > survfit() only returns an object of the following structure > > n events median 0.9LCL 0.9UCL > 55.000 55.000 1.033 0.696 1.637 > > Can you tell me how I can calculate a survival- or baseline-function out > of these values and how I extract the values from the object? I?m sure > the calculation is done by the corresponding plot-routine, but I > couldn?t find that one either. > > Regards > > Bernhard > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
David Winsemius
2009-Feb-17 16:03 UTC
[R] Survival-Analysis: How to get numerical values from survfit (and not just a plot)?
I seriously doubt that a survfit object could only contain that information. I suspect that you are erroneously thinking that what print.survfit offers is the entire story. What does str(survfit(<formula>, data=<dataframe>) ) show you? > data(aml) > aml.mdl <- survfit(Surv(time, status) ~ x, data=aml) # this is with survfit.Design since I load Hmisc/Design by default now. > str(aml.mdl) List of 18 $ n : int 23 $ time : num [1:20] 9 13 18 23 28 31 34 45 48 161 ... $ n.risk : num [1:20] 11 10 8 7 6 5 4 3 2 1 ... $ n.event : num [1:20] 1 1 1 1 0 1 1 0 1 0 ... $ surv : num [1:20] 0.909 0.818 0.716 0.614 0.614 ... $ type : chr "right" $ ntimes.strata: Named int [1:2] 10 10 ..- attr(*, "names")= chr [1:2] "1" "2" $ strata : Named num [1:2] 10 10 ..- attr(*, "names")= chr [1:2] "Maintained" "Nonmaintained" $ strata.all : Named int [1:2] 11 12 ..- attr(*, "names")= chr [1:2] "Maintained" "Nonmaintained" $ std.err : num [1:20] 0.0953 0.1421 0.1951 0.2487 0.2487 ... $ upper : num [1:20] 0.987 0.951 0.899 0.835 0.835 ... $ lower : num [1:20] 0.508 0.447 0.35 0.266 0.266 ... $ conf.type : chr "log-log" $ conf.int : num 0.95 $ maxtime : num 161 $ units : chr "Day" $ time.label : chr "time" $ call : language survfit(formula = Surv(time, status) ~ x, data = aml) - attr(*, "class")= chr "survfit" > I also don't think survfit returns a Cox model. On Feb 17, 2009, at 10:37 AM, Bernhard Reinhardt wrote:> Hi! > > I came across R just a few days ago since I was looking for a > toolbox for cox-regression. > > I?ve read > "Cox Proportional-Hazards Regression for Survival Data > Appendix to An R and S-PLUS Companion to Applied Regression" from > John Fox. > > As described therein plotting survival-functions works well > (plot(survfit(model))). But I?d like to do some manipulation with > the survival-functions before plotting them e.g. dividing one > survival-function by another. > > survfit() only returns an object of the following structure > > n events median 0.9LCL 0.9UCL > 55.000 55.000 1.033 0.696 1.637 > > Can you tell me how I can calculate a survival- or baseline-function > out of these values and how I extract the values from the object? I > ?m sure the calculation is done by the corresponding plot-routine, > but I couldn?t find that one either. > > Regards > > Bernhard > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Eik Vettorazzi
2009-Feb-17 16:44 UTC
[R] Survival-Analysis: How to get numerical values from survfit (and not just a plot)?
Hi Bernhard, I'm wondering what you will expect to get in "dividing" two proportional survival curves from a fitted cox model. Anyway, you can provide a newdata object to the survfit function containing any combination of cofactors you are interested in and then use summary, eg: fit <- coxph( Surv(futime,fustat)~resid.ds+rx+ecog.ps,data=ovarian) summary(survfit( fit,newdata=data.frame(rx=1, ecog.ps=2, resid.ds=0))) hth. Bernhard Reinhardt schrieb:> Hi! > > I came across R just a few days ago since I was looking for a toolbox > for cox-regression. > > I?ve read > "Cox Proportional-Hazards Regression for Survival Data > Appendix to An R and S-PLUS Companion to Applied Regression" from John > Fox. > > As described therein plotting survival-functions works well > (plot(survfit(model))). But I?d like to do some manipulation with the > survival-functions before plotting them e.g. dividing one > survival-function by another. > > survfit() only returns an object of the following structure > > n events median 0.9LCL 0.9UCL > 55.000 55.000 1.033 0.696 1.637 > > Can you tell me how I can calculate a survival- or baseline-function > out of these values and how I extract the values from the object? I?m > sure the calculation is done by the corresponding plot-routine, but I > couldn?t find that one either. > > Regards > > Bernhard > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790