Skip to content

Weibull survival regression

6 messages · Eric Lim, Ales Ziberna, Göran Broström +2 more

#
I do not belive there is a plot method for survreg object.

#You can plot survuval using the coeficents it returns:
curve(exp(-(exp(-lung.wbs$coef[1])*x)^(1/lung.wbs$scale)))

#Here is an exemple for "lung" data from library "survival"
library(survival)
data(lung)
lung.wbs <- survreg( Surv(time, status)~1, data=lung, dist='weibull')
plot(survfit(Surv(time,status),data=lung))
curve(exp(-(exp(-lung.wbs$coef[1])*x)^(1/lung.wbs$scale)),col="red",add=T)


----- Original Message ----- 
From: "Eric Lim" <eric.lim at cvsnet.org>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, November 23, 2004 7:56 AM
Subject: [R] Weibull survival regression


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

Using the Design package:

lung.wbd <- psm (Surv (futime, status)~ 1, dist="weibull", data=lung,
na.action=na.omit)

survplot(lung.wbd)

Returns the error msg:

Error in survplot.Design(lung.wbd) : fit does not have design
information

Using the eha package (I have not figured out how to get baseline
function only, but have used ht=0/1 hypertension as a covariate):

lung.wbe <- weibreg (Surv (futime, status)~ ht, y=T, data=audit,
na.action=na.omit)

plot (lung.wbe)

I get a plot with hazard (y) against age (x) ??? I cannot control the
axes with labeling and any other covariate gets the same plot.

I have tried using covariates in the Design and Survival packages, but
they always return the same error msgs. I realise that the former 2 are
AFT survival models, but even when I convert the object with pphsm() in
the Design package, I get the same errors.

Please can anyone enlighten me as to what I seem to be doing /
understanding wrongly?

Regards,

Eric Lim
Papworth Hospital
Cambridge, UK


           futime status
 [1,]  0.40000000      1
 [2,]  0.80000000      1
 [3,]  7.10000000      1
 [4,]  3.00000000      1
 [5,]  0.63333333      1
 [6,]  9.93333333      1
 [7,]  0.50000000      1
 [8,]  6.93333333      1
 [9,] 23.33333333      1
[10,]  1.73333333      1
[11,] 24.66666667      1
[12,]  0.06666667      1
[13,] 14.43333333      1
[14,]  8.83333333      0
[15,] 27.53333333      0




______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html
#
PS: You can plot hazard in a similar way

Best regards,
Ale. .iberna

----- Original Message ----- 
From: "Eric Lim" <eric.lim at cvsnet.org>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, November 23, 2004 7:56 AM
Subject: [R] Weibull survival regression


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

Using the Design package:

lung.wbd <- psm (Surv (futime, status)~ 1, dist="weibull", data=lung,
na.action=na.omit)

survplot(lung.wbd)

Returns the error msg:

Error in survplot.Design(lung.wbd) : fit does not have design
information

Using the eha package (I have not figured out how to get baseline
function only, but have used ht=0/1 hypertension as a covariate):

lung.wbe <- weibreg (Surv (futime, status)~ ht, y=T, data=audit,
na.action=na.omit)

plot (lung.wbe)

I get a plot with hazard (y) against age (x) ??? I cannot control the
axes with labeling and any other covariate gets the same plot.

I have tried using covariates in the Design and Survival packages, but
they always return the same error msgs. I realise that the former 2 are
AFT survival models, but even when I convert the object with pphsm() in
the Design package, I get the same errors.

Please can anyone enlighten me as to what I seem to be doing /
understanding wrongly?

Regards,

Eric Lim
Papworth Hospital
Cambridge, UK


           futime status
 [1,]  0.40000000      1
 [2,]  0.80000000      1
 [3,]  7.10000000      1
 [4,]  3.00000000      1
 [5,]  0.63333333      1
 [6,]  9.93333333      1
 [7,]  0.50000000      1
 [8,]  6.93333333      1
 [9,] 23.33333333      1
[10,]  1.73333333      1
[11,] 24.66666667      1
[12,]  0.06666667      1
[13,] 14.43333333      1
[14,]  8.83333333      0
[15,] 27.53333333      0




______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
#
On Tue, Nov 23, 2004 at 06:56:56AM -0000, Eric Lim wrote:
Right, plot.weibreg in eha is very poorly implemented, newdata does not
work, you cannot change labels of the plot, etc. I hope to get time to do
it right soon, but...

Anyway, the problem is simple to solve: You get the estimates of scale and
shape of the Weibull distribution (or their logarithms). Since eha uses
"standard R parametrization", you can simply plot the functions 
"dweibull / pweibull( , lower.tail = FALSE)" with the estimated parameters
inserted for the hazard function, and "pweibull( , lower.tail = FALSE)" for
the survival function.

[...]

G??ran
#
Eric Lim wrote:
You don't need to specify na.action here.
survplot only works when there is at least one covariate.  Sorry.  Maybe 
someday ...

  -Frank Harrell

  
    
#
On Tue, 23 Nov 2004, Eric Lim wrote:

            
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