[R] Survival statistics--displaying multiple plots

2007-05-02 Thread Gregory Pierce
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,meld10)) 

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
meld10, 10meld20, and meld20. I am unsure about how to go about this.

Any suggestions would be appreciated.

Greg

__
R-help@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Gregory Pierce
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:[EMAIL PROTECTED] 
Sent: Wednesday, May 02, 2007 10:21 PM
To: 'r-help@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,meld10)) 

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
meld10, 10meld20, and meld20. I am unsure about how to go about this.

Any suggestions would be appreciated.

Greg

__
R-help@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Robert A LaBudde
? layout()
? par()

E.g.,

layout(matrix(c(1,2,3),1,3,byrow=TRUE) #3 plots side-by-side

Then use plot() three times to generate each of your graphs.

At 11:14 PM 5/2/2007, Greg 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:[EMAIL PROTECTED]
Sent: Wednesday, May 02, 2007 10:21 PM
To: 'r-help@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,meld10))

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
meld10, 10meld20, and meld20. I am unsure about how to go about this.

Any suggestions would be appreciated.


Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

__
R-help@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Petr Klasterecky
Have a look at
?lines
?points
?plot - the option add, add=TRUE

You will have to specify proper limits on both axes, otherwise you may 
only see parts of the graphs. Some functions in the survival library 
also allow stratified analyses in which case the plots account for 
different strata.

Petr

Gregory Pierce napsal(a):
 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:[EMAIL PROTECTED] 
 Sent: Wednesday, May 02, 2007 10:21 PM
 To: 'r-help@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,meld10)) 
 
 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
 meld10, 10meld20, and meld20. I am unsure about how to go about this.
 
 Any suggestions would be appreciated.
 
 Greg
 
 __
 R-help@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.
 

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic

__
R-help@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Gregory Pierce
Thanks for replying Robert. Forgive me, it might be the hour or my
limitations, but I am a little unclear on how to implement your suggestion. 

In my original example,

plot(survfit(Surv(days,status==1),subset(tips,meld10))

A plot of the fraction of patients surviving following the procedure against
the number of days since the procedure would be generated for patients with
meld scores of less than 10. 

Similarly, if I wanted to generate a survival curve of patients with scores
of between 10 and 20, I can with the following:

 plot(survfit(Surv(days,status==1),subset(tips,meld10  meld 20))


And for patients with meld20,

plot(survfit(Surv(days,status==1),subset(tips,meld20))


But how do I display the curves in each cadre (meld10, 10meld20, and
meld20) on the same chart?

 
-Original Message-
From: Robert A LaBudde [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 02, 2007 11:48 PM
To: Gregory Pierce
Subject: Re: [R] Survival statistics--displaying multiple plots

? layout()
? par()

E.g.,

layout(matrix(c(1,2,3),1,3,byrow=TRUE) #3 plots side-by-side

Then use plot() three times to generate each of your graphs.

At 11:14 PM 5/2/2007, Greg 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:[EMAIL PROTECTED]
Sent: Wednesday, May 02, 2007 10:21 PM
To: 'r-help@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,meld10))

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
meld10, 10meld20, and meld20. I am unsure about how to go about this.

Any suggestions would be appreciated.


Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

__
R-help@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Marc Schwartz
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:[EMAIL PROTECTED] 
 Sent: Wednesday, May 02, 2007 10:21 PM
 To: 'r-help@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,meld10)) 
 
 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
 meld10, 10meld20, and meld20. I am unsure about how to go about this.
 
 Any suggestions would be appreciated.
 
 Greg
 
 __
 R-help@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@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Gregory Pierce
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:[EMAIL PROTECTED] 
Sent: Thursday, May 03, 2007 12:18 AM
To: Gregory Pierce
Cc: r-help@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:[EMAIL PROTECTED] 
 Sent: Wednesday, May 02, 2007 10:21 PM
 To: 'r-help@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,meld10)) 
 
 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
 meld10, 10meld20, and meld20. I am unsure about how to go about this.
 
 Any suggestions would be appreciated.
 
 Greg
 
 __
 R-help@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@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.


Re: [R] Survival statistics--displaying multiple plots

2007-05-02 Thread Robert A LaBudde
The layout() function below states there are to be 3 graphs on the 
first row, side by side.

Each time you plot, R applies the graph to the next free position on 
the layout. After 3 plots with your different boolean subsets, you 
end up with 3 graphs side by side.

If this is not what you want (you asked for this in your first 
request), and instead you want 3 curves on the same, single graph, 
use plot() for the first curve(s) and then use lines() to add the 
additional curves.

Check the survfit() object to see how to pick off individual times 
and survival curves by subscripting.

At 12:09 AM 5/3/2007, Greg wrote:
Thanks for replying Robert. Forgive me, it might be the hour or my
limitations, but I am a little unclear on how to implement your suggestion.

In my original example,

 plot(survfit(Surv(days,status==1),subset(tips,meld10))

A plot of the fraction of patients surviving following the procedure against
the number of days since the procedure would be generated for patients with
meld scores of less than 10.

Similarly, if I wanted to generate a survival curve of patients with scores
of between 10 and 20, I can with the following:

  plot(survfit(Surv(days,status==1),subset(tips,meld10  meld 20))


And for patients with meld20,

 plot(survfit(Surv(days,status==1),subset(tips,meld20))


But how do I display the curves in each cadre (meld10, 10meld20, and
meld20) on the same chart?


-Original Message-
From: Robert A LaBudde [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 02, 2007 11:48 PM
To: Gregory Pierce
Subject: Re: [R] Survival statistics--displaying multiple plots

? layout()
? par()

E.g.,

layout(matrix(c(1,2,3),1,3,byrow=TRUE) #3 plots side-by-side

Then use plot() three times to generate each of your graphs.

At 11:14 PM 5/2/2007, Greg 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:[EMAIL PROTECTED]
 Sent: Wednesday, May 02, 2007 10:21 PM
 To: 'r-help@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,meld10))
 
 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
 meld10, 10meld20, and meld20. I am unsure about how to go about this.
 
 Any suggestions would be appreciated.


Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

__
R-help@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] Survival Statistics

2006-06-05 Thread Gregory Pierce
Hello friends and fellow R users,

I have a problem to which I have been unable to find a solution: I am
gathering survival data on patients undergoing treatment with a new kind
of stent. I want to generate survival data and plot survival curves of
these patients based (among other things) on the treating physician. My
data set has been tabulated in the following manner:

Date(the date the stent was implanted)   
Description (diameter of the stent)
Patient (name)
MRN (ID number)
Age (age in years of the patient)
Physician (last name of the implanting physician)
status (0 or 1)
days (days alive since the stenting procedure)
Cr 
INR
BR
MELD

The data set has over ten physicians. Following the examples in
Introductory Statistics with R I have been able to draw cumulative
survival curves and even the survival curves by physician but there are
so many curves on the graph when I do, it is uninterpretable.

I would just like to plot the survival curves of say the top two or
three. That would be much more useful. I have been able to create a
Surv object out of my own survival data and that of a colleague in the
following way using indexing:

Surv(days[viatorr[6]==Pierce|
viatorr[6]==Ed],status[viatorr[6]==Pierce|viatorr[6]==Ed]==1)
[1] 558+ 474+ 472+ 446+ 443+ 429+ 401  395+ 390  390+ 362+ 354  344+ 342
326+
[16] 300+ 284+ 280+ 246+ 237+ 233+ 233  230+ 230+ 225+ 215  199+ 191+
191  184+
[31] 161+ 153  150  129+  69+  52+  38+

I can get even further:

surv.ee.gp-Surv(days[viatorr[6]==Pierce|
viatorr[6]==Ed],status[viatorr[6]==Pierce|viatorr[6]==Ed]==1)
 survfit(surv.ee.gp)
Call: survfit(formula = surv.ee.gp)

  n  events  median 0.95LCL 0.95UCL
 37   9 Inf 390 Inf

But now if I want to plot the data using the following command

plot(survfit(surv.ee.gp)~Physician)

I receive an error:

Error in model.frame(formula, rownames, variables, varnames, extras,
extranames,  :
invalid variable type

I have tried indexing Physician, but that fails as well:

 plot(survfit(surv.ee.gp)~Physician[viatorr[6]==Pierce|
viatorr[6]==Ed]==1)
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames,  :
invalid variable type

I apologize for this long-winded explanation but I am new to this
program and even newer to Statistics and I wanted to make sure the
context and problem were clear (hopefully).

I would appreciate any guidance in a way forward. 

Thank you,
Greg

__
R-help@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