[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 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 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.


[R] Calculating survival for set time intervals

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

I have successfully tabulated and entered my survival data into R and
have generated survival curves. But I would like to be able to determine
what the survival rates are now at one month, three months, six months
and one year.

I have a data set, via.wall, which I have entered into R, and which
generates the following Surv object:

Surv(Days,Status==1)
  [1] 648+   3  109  241   997  849+ 1053+ 539+ 121   42  490
21  870+
 [16] 175   20  434  289  826+ 831+ 664  698+   5   24  655+  187+
85+  65+
 [31] 547+   81   55+  69  499+ 448+   0  158+  31  246+ 230+  19
118+  54
 [46]  48+  45+  21+ 670+ 585  558+ 544+ 494  481+ 474+ 472+ 461  447
446+ 443+
 [61] 429+ 423+ 401  395+ 390  390+ 389+ 383+ 383+ 373+ 362+ 354  344+
342  336+
 [76] 335+ 326+ 306  300+ 292  284+ 280+ 271  246+ 237+ 234  233+ 233
230+ 230+
 [91] 226+ 225+ 218+ 215  211+ 199+ 191+ 191  190+ 184+ 169+ 163+ 161+
153  150
[106] 129+ 110+ 107+ 100+  84+  77+  69+  52+  38+  11+
 names(wall.via)
 [1] Description Patient Physician   MRN Age
 [6] Status  DaysCr  INR BR
[11] MELDtype

I can guess pretty accurately by looking at the graph what the survival
rates are at each interval, but I would like to understand how to
instruct R to calculate it. Hope I have made this clear. I am just a
beginner, so forgive me if this is trivial. It just isn't clear to me.

Thanks,
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


[R] Selective Survival Statistics with R

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


Re: [R] Selective Survival Statistics with R

2006-06-05 Thread Gregory Pierce
On Mon, 2006-06-05 at 18:54 -0400, Barker, Chris [SCIUS] wrote:
 Its probably easiest/fastest for you either to subset your dataset
 first, or else simply use the subset option in survfit()
 
  e.g. 
 
 survfit( ) has a subset option,  
 survfit( Surv( , ) ~ physician , subset=='Jones)
 
Chris,

Thank you very much for your kind reply. Using subset worked. I had to
modify the syntax a little from what you posted:

survfit(Surv(days,status==1)~Physician,subset(viatorr,viatorr[6]==Pierce)

where viatorr is the name of my data set.

Applying plot to the function above generated a survival curve for my
patients. I was also able to plot survival curves for other physicians
as well. This is great!

__
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


[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


Re: [R] Selective Survival Statistics with R

2006-06-05 Thread Gregory Pierce
On Mon, 2006-06-05 at 17:04 -0700, Thomas Lumley wrote:
 On Mon, 5 Jun 2006, Gregory Pierce wrote:
  On Mon, 2006-06-05 at 18:54 -0400, Barker, Chris [SCIUS] wrote:
  Its probably easiest/fastest for you either to subset your dataset
  first, or else simply use the subset option in survfit()
 
   e.g.
 
  survfit( ) has a subset option,
  survfit( Surv( , ) ~ physician , subset=='Jones)
 
  Chris,
 
  Thank you very much for your kind reply. Using subset worked. I had to
  modify the syntax a little from what you posted:
 
  survfit(Surv(days,status==1)~Physician,subset(viatorr,viatorr[6]==Pierce)
 
  where viatorr is the name of my data set.
 
 An example of another approach is given in the example on the help page 
 for survfit
 
 You could do
curves - survfit(Surv(days,status==1)~Physician, data=viatorr)
plot(curves[1])
plot(curves[2])
 etc.
 
   -thomas

That also worked great! Thanks. This makes me very,very happy!!! I
can now go to our statistician without looking like a complete idiot and
I can get to work collecting survival data on our patients who had the
old-fashioned bare-metal Wallstent. Looking back in this way provides a
very interesting and humbling perspective.

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