[R] plot(survfit(fitCox)) graph shows one line - should show two
Thomas Lumley
tlumley at u.washington.edu
Mon May 11 01:15:35 CEST 2009
On Sun, 10 May 2009, John Sorkin wrote:
> R 2.8.1
> Windows XP
>
> I am trying to plot the results of a coxph using plot(survfit()). The plot
>should, I believe, show two lines one for survival in each of two treatment
>(Drug) groups, however my plot shows only one line. What am I doing wrong?
Expecting two lines. To get survival curves from a Cox model you need to specify the covariate values. If you don't, you get the baseline survival (ie, at the mean covariate values).
Look at the example on ?survfit.coxph
fit <- coxph(Surv(futime, fustat) ~ age, data = ovarian)
plot(survfit(fit, newdata=data.frame(age=60)),
xscale=365.25, xlab = "Years", ylab="Survival")
This plots the fitted curve for age 60. If you wanted multiple ages you can specify them, eg,
plot(survfit(fit, newdata=data.frame(age=c(40,50,60))),
xscale=365.25, xlab = "Years", ylab="Survival")
gives three curves.
-thomas
> My code is reproduced below, my figure is attached to this EMail message.
> John
>
>
>> #Create simple survival object
>> GVHDdata<-list(Time=GVHD$Time,Time30=(GVHD$Time)/30,
> + Age=GVHD$Age,Drug=GVHD$Drug,Died=GVHD$Died,
> + AgeGrp=cut(GVHD$Age,breaks=c(0,15,25,45)))
>>
>> summary(GVHD$Drug)
> MTX MXT+CSP
> 32 32
>>
>>
>>
>> fit0<-coxph(Surv(Time30,Died)~Drug,data=GVHDdata)
>> summary(fit0)
> Call:
> coxph(formula = Surv(Time30, Died) ~ Drug, data = GVHDdata)
>
> n= 64
> coef exp(coef) se(coef) z p
> Drug[T.MXT+CSP] -1.15 0.316 0.518 -2.23 0.026
>
> exp(coef) exp(-coef) lower .95 upper .95
> Drug[T.MXT+CSP] 0.316 3.16 0.115 0.871
>
> Rsquare= 0.086 (max possible= 0.915 )
> Likelihood ratio test= 5.75 on 1 df, p=0.0165
> Wald test = 4.96 on 1 df, p=0.026
> Score (logrank) test = 5.52 on 1 df, p=0.0188
>
>>
>>
>> plot(survfit(fit0))
>
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:7}}
More information about the R-help
mailing list