Re: [R] Weibull survival regression
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 [EMAIL PROTECTED] To: [EMAIL PROTECTED] 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.4000 1 [2,] 0.8000 1 [3,] 7.1000 1 [4,] 3. 1 [5,] 0.6333 1 [6,] 9.9333 1 [7,] 0.5000 1 [8,] 6.9333 1 [9,] 23. 1 [10,] 1.7333 1 [11,] 24.6667 1 [12,] 0.0667 1 [13,] 14.4333 1 [14,] 8.8333 0 [15,] 27.5333 0 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Weibull survival regression
PS: You can plot hazard in a similar way Best regards, Ale iberna - Original Message - From: Eric Lim [EMAIL PROTECTED] To: [EMAIL PROTECTED] 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.4000 1 [2,] 0.8000 1 [3,] 7.1000 1 [4,] 3. 1 [5,] 0.6333 1 [6,] 9.9333 1 [7,] 0.5000 1 [8,] 6.9333 1 [9,] 23. 1 [10,] 1.7333 1 [11,] 24.6667 1 [12,] 0.0667 1 [13,] 14.4333 1 [14,] 8.8333 0 [15,] 27.5333 0 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Weibull survival regression
On Tue, Nov 23, 2004 at 06:56:56AM -, 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 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. 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 -- Göran Broströmtel: +46 90 786 5223 Department of Statistics fax: +46 90 786 6614 Umeå University http://www.stat.umu.se/egna/gb/ SE-90187 Umeå, Sweden e-mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Weibull survival regression
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 Using the Design package: lung.wbd - psm (Surv (futime, status)~ 1, dist=weibull, data=lung, na.action=na.omit) You don't need to specify na.action here. survplot(lung.wbd) Returns the error msg: Error in survplot.Design(lung.wbd) : fit does not have design information survplot only works when there is at least one covariate. Sorry. Maybe someday ... -Frank Harrell Regards, Eric Lim Papworth Hospital Cambridge, UK -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Weibull survival regression
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 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Weibull survival regression
A big thank you to everyone who responded... Using Ale iberna solution with the lung dataset, I obtained: plot(survfit(Surv(time,status),data=lung)) Error in Surv(time, status) : Time variable is not numeric In addition: Warning message: is.na() applied to non-(list or vector) in: is.na(time) Using Thomas Lumley's solution with the lung dataset, I obtained: curve(pweibull(x, scale=1/coef(lung.wbs), shape=1/lung.wbs$scale, lower.tail=FALSE),from=0, to=max(lung$time)) A Weibull survival plot appearing as a 90 degree `L' at the extremes of the plot I managed to obtain the solution by combining the two solutions: lung.wbs - survreg( Surv(futime, status)~ 1, data=lung, dist='weibull') plot (survfit(Surv(futime,status)~1, data=lung)) curve (exp (- (exp( lung.wbs$coef[1])*x)^(1/lung.wbs$scale)), col=black, add=T, from=0, to=30) Kind regards, Eric Lim Papworth Hospital Cambridge, UK __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Weibull survival regression
On Tue, 23 Nov 2004, Eric Lim wrote: Using Thomas Lumley's solution with the lung dataset, I obtained: curve(pweibull(x, scale=1/coef(lung.wbs), shape=1/lung.wbs$scale, lower.tail=FALSE),from=0, to=max(lung$time)) That's because you read the part of the message where I got the reparametrization wrong, rather than the part where I got right. It should be curve(pweibull(x, scale=exp(coef(lung.wbs)), shape=1/lung.wbs$scale, lower.tail=FALSE),from=0, to=max(lung$time)) -thomas __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[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.4000 1 [2,] 0.8000 1 [3,] 7.1000 1 [4,] 3. 1 [5,] 0.6333 1 [6,] 9.9333 1 [7,] 0.5000 1 [8,] 6.9333 1 [9,] 23. 1 [10,] 1.7333 1 [11,] 24.6667 1 [12,] 0.0667 1 [13,] 14.4333 1 [14,] 8.8333 0 [15,] 27.5333 0 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html