[R] Survival statistics--displaying multiple plots

Gregory Pierce prcg at mac.com
Thu Jul 31 23:14:12 CEST 2008


Marc,

Thank you so much! Your solution is perfect! I hadn't known about the "cut"
function. The graph is precisely what I needed. I have the ISwR book but not
anything more advanced. Need to get some more advanced books, maybe?

I have been stubbornly working on this for a few hours now, and getting
nowhere. I wish I were able to repay in some way. 

Thank you!

Greg 



-----Original Message-----
From: Marc Schwartz [mailto:marc_schwartz at comcast.net] 
Sent: Thursday, May 03, 2007 12:18 AM
To: Gregory Pierce
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Survival statistics--displaying multiple plots

Greg,

I suspect that you want something like this:

Use the 'aml' dataset and create a 'meld' column with random values from
1:25:

library(survival)

set.seed(1)
aml$meld <- sample(25, 23, replace = TRUE)

> aml$meld
 [1]  7 10 15 23  6 23 24 17 16  2  6  5 18 10 20 13 18 25 10 20 24  6
[23] 17


Now use cut() to create a 3 level factor from the values in 'meld':

aml$meld.grp <- cut(aml$meld, breaks = c(-Inf, 10, 20, Inf))

> aml$meld.grp
 [1] (-Inf,10] (-Inf,10] (10,20]   (20, Inf] (-Inf,10] (20, Inf]
 [7] (20, Inf] (10,20]   (10,20]   (-Inf,10] (-Inf,10] (-Inf,10]
[13] (10,20]   (-Inf,10] (10,20]   (10,20]   (10,20]   (20, Inf]
[19] (-Inf,10] (10,20]   (20, Inf] (-Inf,10] (10,20]  
Levels: (-Inf,10] (10,20] (20, Inf]


Now, let's do the plot, grouping by 'meld.grp':

plot(survfit(Surv(time, status) ~ meld.grp, data = aml), 
     col = 1:3, legend.text = levels(aml$meld.grp),
     legend.pos = 1)


If this is close, see ?cut for creating a factor from a continuous
vector.

You can of course further tweak the plot aesthetics as you desire.

HTH,

Marc Schwartz



On Wed, 2007-05-02 at 23:14 -0400, Gregory Pierce wrote:
> I should clarify. I can generate plots for each category individually but
> not for all three on the same chart.
> 
> Greg
> 
> -----Original Message-----
> From: Gregory Pierce [mailto:pierce.gregory at gmail.com] 
> Sent: Wednesday, May 02, 2007 10:21 PM
> To: 'r-help at stat.math.ethz.ch'
> Subject: Survival statistics--displaying multiple plots
> 
> Hello all!
> 
> I am once again analyzing patient survival data with chronic liver
disease. 
> 
> The severity of the liver disease is given by a number which is
continuously
> variable. I have referred to this number as "meld"--model for end stage
> liver disease--which is the result of a mathematical calculation on
> underlying laboratory values. So, for example, I can generate a
Kaplan-Meier
> plot of patients undergoing a TIPS procedure with the following:
> 
> >plot(survfit(Surv(days,status==1),subset(tips,meld<10)) 
> 
> where "tips" is my data set, "days" is the number of days alive, and meld
is
> the meld score.
> 
> What I would like to do is display the survival graphs of patients with
> meld<10, 10<meld<20, and meld>20. I am unsure about how to go about this.
> 
> Any suggestions would be appreciated.
> 
> Greg
> 
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list