[R] Weibull survival regression

Thomas Lumley tlumley at u.washington.edu
Tue Nov 23 16:21:41 CET 2004


On Tue, 23 Nov 2004, Eric Lim wrote:

> Dear R users,
>
> Please can you help me with a relatively straightforward problem that I
> am struggling with? I am simply trying to plot a baseline survivor and
> hazard function for a simple data set of lung cancer survival where
> `futime' is follow up time in months and status is 1=dead and 0=alive.
>
> Using the survival package:
>
> lung.wbs <- survreg( Surv(futime, status)~ 1, data=lung, dist='weibull')
>
> plot (lung.wbs)
>
> Returns the error msg:
>
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>        x and y lengths differ

Yes. There isn't a plot method for survreg() (and if there were, it 
wouldn't do this).

The right thing to try would have been
   plot(survfit(lung.wbs)
but that doesn't work either.

You can get the curve you want with
   curve(pweibull(x, scale=exp(coef(lung.wbs)), shape=1/lung.wbs$scale,
    lower.tail=FALSE),from=0, to=max(lung$futime))

where most of the complications come from the fact that survreg() and 
pweibull() parametrise the Weibull distribution differently.

Incidentally, this works quite nicely on the built-in lung cancer example 
data set, showing surprisingly good fit to a Weibull.

   data(lung)
   lung.wbs <- survreg( Surv(time, status)~ 1, data=lung, dist='weibull')
   curve(pweibull(x, scale=1/coef(lung.wbs), shape=1/lung.wbs$scale,
      lower.tail=FALSE),from=0, to=max(lung$time))
   lines(survfit(Surv(time,status)~1, data=lung), col="red")


 	-thomas




More information about the R-help mailing list