Skip to content
Prev 312177 / 398503 Next

Plotting an adjusted survival curve

Dear Terry and David
Thank you so much for your rapid and helpful replies!
I've changed tack slightly and decided to focus on the effect modifiers which had the greatest effect on the outcome of the trial (HowmanyZonnic_Q and WISDMPDM)
I've tried to follow your example on page 16 of the manuscript you emailed me, but I get an error which I think is related to trying to do maths on two matrices which are of different dimensions I think???
This is my code:
KM.object.coxph5 <- coxph(Surv(whenfailed,failed) ~ strata(Treatment)+HowmanyZonnic_Q+WISDMPDM,survmat)
asdist <- table(HowmanyZonnic_Q,WISDMPDM)
uage <- as.numeric(dimnames(asdist)[[1]])
tdata <- expand.grid(HowmanyZonnic_Q=uage, WISDMPDM=uage) #This appears to be a table of all the possible combinations of HowmanyZonnic_Q and WISDMPDM
par(mfrow=c(1,2))
sfit4a <- survfit(KM.object.coxph5, newdata=tdata, se.fit=FALSE)
sfit4a$surv <- sfit4a$surv %*% c(asdist/sum(asdist)) #Error in sfit4a$surve %*% c(asdist/sum(asdist)) :   non-conformable arguments
#sfit4a$surv is a table of 10 rows and 25 columns
#c(asdist/sum(asdist)) is a vector with a length of 420
I hope I am not sapping your patience with this question
Thank you - you guys are awesome
Best wishes
Brent

-----Original Message-----
From: Terry Therneau [mailto:therneau at mayo.edu] 
Sent: Tuesday, 27 November 2012 4:03 a.m.
To: r-help at r-project.org; Brent Caldwell
Cc: David Winsemius
Subject: Re: Plotting an adjusted survival curve

First a statistical issue: The survfit routine will produce predicted survival curves for any requested combination of the covariates in the original model.  This is not the same thing as an "adjusted" survival curve.  Confusion on this is prevalent, however.  True adjustment requires a population average over the confounding factors and is closely related to the standardized incidence ratio concept found in epidemiology.

To answer your technical question:
    fit <- coxph(Surv(.........
    mysurv <- survfit(fit, newdata= mydata) This will give a set of predicted curves, one for each observation in mydata.  If we assume 2 treatments and 4 ethnicities, this means that there are 8 possible predicted curves.  You can certainly take the curves for "trt=1, white" and "trt=2, white", plot them together on one graph, and call this your "adjusted" survival curves; the mydata data set would have two observations.  This is not a correct label but is certainly common.

Terry Therneau
On 11/26/2012 05:00 AM, r-help-request at r-project.org wrote: