[R] Plotting coxph survival curves

Terry Therneau therneau at mayo.edu
Wed Jan 25 13:58:13 CET 2012


>From a fitted Cox model you can get the predicted survival curve for any
particular covariates.  To do this make a dummy data set containing what
you want.  For instance
> dummy <- data.frame(MS=c('mated','virgin'),
	              weight=c(5,5)
                      laid =c(200,200))
> survfit(F.cox.weight, newdata=dummy)

will create two curves for this particular weight/laid compbination. If
no newdata argument is given the routine uses the mean of each covariate
as the values for which to plot a curve.  I know, it's often a terrible
default, but I bowed to history when creating the function.  For a case
like yours in particular the mean of the 0/1 "MS" column in the X matrix
does not correspond to a biological possibility -- you got the curve for
some sort of Frankenstein bug.

Terry T

----------------- begin included message ---------------
Hi,

I am attempting to plot survival curves estimated by cox proportional
hazards regression model.  The formula for the model is this:

F.cox.weight <- coxph(Surv(Lifespan, Status) ~ MS + Weight + Laid +
MS:Laid
+ Weight:Laid, data = LongF)

MS = Mating status (mated/virgin)
Weight = adult female weight, continuous covariate
Laid = number of eggs laid by each female, continuous covariate

I want to plot female survival, as estimated by my model, by mating
status
and therefore two survival curves should be plotted.  My code results in
one
survival curve bounded by, what I assume are confidence intervals.

My code for the plot is:

plot(survfit(F.cox.weight), lty=c(1,3), ylab = "Survivorship", xlab =
"Day",
bty="L")
legend(35,0.9,c("Mated","Virgin"), lty=c(1,3), bty = "n")

The plot looks like this:
http://r.789695.n4.nabble.com/file/n4325120/Fig_survival_female.jpg 

Probably a simple bit of code I'm missing!

----- end inclusion ---------



More information about the R-help mailing list