command in survival package

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

command in survival package

Linda Lei
Hi there,

 

I have a question about one command sentence when I follow the example
in the book of "Survival analysis in S":

 

 > aml1<-aml[aml$group==1]

 

but I got the error warning: NULL data frame with 23 rows

 

Thus, I couldn't keep going on the next command:

 

esf.fit<-survfit(Surv(aml1,status)~1).

 

and also when I try

 

> aml1<-aml[aml$group==1,]

> aml1

 

I got

 

[1] time   status x    

<0 rows> (or 0-length row.names)

 

 

Could you please help me with these questions? I'm stuck here. Thank you
very much!

 

Cheers,

Linda


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: command in survival package

Thomas Lumley
On Fri, 20 Jan 2006, Linda Lei wrote:

> Hi there,
>
>
>
> I have a question about one command sentence when I follow the example
> in the book of "Survival analysis in S":
>
> > aml1<-aml[aml$group==1]

If this is really what the book says you should probably complain to the
author.  However, if it says
   aml1<-aml[aml$group==1,]
then you show type that instead.

It is hard to be sure, because you don't say where the `aml' data set
comes from.  It can't be the one in the survival package as this doesn't
have a variable called "group"

>
> Thus, I couldn't keep going on the next command:
>
> esf.fit<-survfit(Surv(aml1,status)~1).
>

This looks implausible as well. I would have expected something like
   esf.fit<-survfit(Surv(time,status)~1, data=aml1)


  -thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: command in survival package

Marc Schwartz (via MN)
On Fri, 2006-01-20 at 15:27 -0800, Thomas Lumley wrote:

> On Fri, 20 Jan 2006, Linda Lei wrote:
>
> > Hi there,
> >
> >
> >
> > I have a question about one command sentence when I follow the example
> > in the book of "Survival analysis in S":
> >
> > > aml1<-aml[aml$group==1]
>
> If this is really what the book says you should probably complain to the
> author.  However, if it says
>    aml1<-aml[aml$group==1,]
> then you show type that instead.
>
> It is hard to be sure, because you don't say where the `aml' data set
> comes from.  It can't be the one in the survival package as this doesn't
> have a variable called "group"
>
> >
> > Thus, I couldn't keep going on the next command:
> >
> > esf.fit<-survfit(Surv(aml1,status)~1).
> >
>
> This looks implausible as well. I would have expected something like
>    esf.fit<-survfit(Surv(time,status)~1, data=aml1)


Correct on both accounts Thomas. The text in the book on page 26 appears
as Linda posted.

However, there is an errata document here:

http://www.crcpress.com/e_products/downloads/download.asp?cat_no=C4088

which shows the corrected text as:

aml1 <- aml[aml$group==1,] # Maintained group only

esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)


HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: command in survival package

Linda Lei
In reply to this post by Linda Lei
Thank you guys.
But I tried the commands and I still get:

> aml1<-aml[aml$group==1,]
> aml1
[1] time   status x    
<0 rows> (or 0-length row.names)
> esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)
Error in Surv(aml1$weeks, status) : Time variable is not numeric
In addition: Warning message:
is.na() applied to non-(list or vector) in: is.na(time)

which still looks confusing. Or are they should be applied in s-plus
instead of R?

Thanks a lot!
Linda


-----Original Message-----
From: Marc Schwartz [mailto:[hidden email]]
Sent: Friday, January 20, 2006 4:49 PM
To: Thomas Lumley
Cc: Linda Lei; [hidden email]
Subject: Re: [R] command in survival package

On Fri, 2006-01-20 at 15:27 -0800, Thomas Lumley wrote:
> On Fri, 20 Jan 2006, Linda Lei wrote:
>
> > Hi there,
> >
> >
> >
> > I have a question about one command sentence when I follow the
example
> > in the book of "Survival analysis in S":
> >
> > > aml1<-aml[aml$group==1]
>
> If this is really what the book says you should probably complain to
the
> author.  However, if it says
>    aml1<-aml[aml$group==1,]
> then you show type that instead.
>
> It is hard to be sure, because you don't say where the `aml' data set
> comes from.  It can't be the one in the survival package as this
doesn't

> have a variable called "group"
>
> >
> > Thus, I couldn't keep going on the next command:
> >
> > esf.fit<-survfit(Surv(aml1,status)~1).
> >
>
> This looks implausible as well. I would have expected something like
>    esf.fit<-survfit(Surv(time,status)~1, data=aml1)


Correct on both accounts Thomas. The text in the book on page 26 appears
as Linda posted.

However, there is an errata document here:

http://www.crcpress.com/e_products/downloads/download.asp?cat_no=C4088

which shows the corrected text as:

aml1 <- aml[aml$group==1,] # Maintained group only

esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)


HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: command in survival package

Thomas Lumley
On Mon, 23 Jan 2006, Linda Lei wrote:

> Thank you guys.
> But I tried the commands and I still get:
>
>> aml1<-aml[aml$group==1,]
>> aml1
> [1] time   status x
> <0 rows> (or 0-length row.names)
>> esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)
> Error in Surv(aml1$weeks, status) : Time variable is not numeric
> In addition: Warning message:
> is.na() applied to non-(list or vector) in: is.na(time)
>
> which still looks confusing. Or are they should be applied in s-plus
> instead of R?

You *still* haven't said where the aml dataset comes from, but as I said
before, it isn't the same as the one built in to R, so you need to load it
somehow.  The one in R has columns called "time", "status" and "x"; you
appear to want one with columns "weeks","status", and "group", and with
"group" being numeric rather than factor.


  -thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: command in survival package

Marc Schwartz (via MN)
On Mon, 2006-01-23 at 10:52 -0800, Thomas Lumley wrote:

> On Mon, 23 Jan 2006, Linda Lei wrote:
>
> > Thank you guys.
> > But I tried the commands and I still get:
> >
> >> aml1<-aml[aml$group==1,]
> >> aml1
> > [1] time   status x
> > <0 rows> (or 0-length row.names)
> >> esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)
> > Error in Surv(aml1$weeks, status) : Time variable is not numeric
> > In addition: Warning message:
> > is.na() applied to non-(list or vector) in: is.na(time)
> >
> > which still looks confusing. Or are they should be applied in s-plus
> > instead of R?
>
> You *still* haven't said where the aml dataset comes from, but as I said
> before, it isn't the same as the one built in to R, so you need to load it
> somehow.  The one in R has columns called "time", "status" and "x"; you
> appear to want one with columns "weeks","status", and "group", and with
> "group" being numeric rather than factor.
>
>
>   -thomas


I don't have the book with me (it's at home), but I suspect that the
problem here is that the 'aml' dataset provided at the aforementioned
web site:

  http://www.crcpress.com/e_products/downloads/download.asp?cat_no=C4088

which is to be used with the code under discussion, was more than likely
not imported into an R session by Linda.

Since one needs to do a:

  > library(survival)

to utilize the R code examples, that loads that package's 'aml' dataset,
resulting in:

  > aml[aml$group==1,]
[1] time   status x    
<0 rows> (or 0-length row.names)

since there is no 'group' column in the built in 'aml' dataset as Thomas
points out.

There is such a structure to the authors' version of the dataset:

> str(read.table("aml.txt", header = TRUE))
`data.frame': 23 obs. of  3 variables:
 $ weeks : num  9 13 13 18 23 28 31 34 45 48 ...
 $ group : num  1 1 1 1 1 1 1 1 1 1 ...
 $ status: num  1 1 0 1 1 0 1 1 0 1 ...


Thus:

>  aml <- read.table("aml.txt", header = TRUE)

> (aml1 <- aml[aml$group==1,])
   weeks group status
1      9     1      1
2     13     1      1
3     13     1      0
4     18     1      1
5     23     1      1
6     28     1      0
7     31     1      1
8     34     1      1
9     45     1      0
10    48     1      1
11   161     1      0


This bring us to the still remaining error in the authors' survival
code, which is not fully corrected in the authors' online errata:

> esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)
Error in Surv(aml1$weeks, status) : object "status" not found


Thus, something like one of the following should be used instead:

> esf.fit <- survfit(Surv(aml1$weeks, aml1$status) ~ 1)

> esf.fit <- with(aml1, survfit(Surv(weeks, status) ~ 1))


> summary(esf.fit)
Call: survfit(formula = Surv(aml1$weeks, aml1$status) ~ 1)

 time n.risk n.event survival std.err lower 95% CI upper 95% CI
    9     11       1    0.909  0.0867       0.7541        1.000
   13     10       1    0.818  0.1163       0.6192        1.000
   18      8       1    0.716  0.1397       0.4884        1.000
   23      7       1    0.614  0.1526       0.3769        0.999
   31      5       1    0.491  0.1642       0.2549        0.946
   34      4       1    0.368  0.1627       0.1549        0.875
   48      2       1    0.184  0.1535       0.0359        0.944


I'll pass on a note to the authors, whose e-mail addresses I have
located via Google.

HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: command in survival package

Marc Schwartz (via MN)
In reply to this post by Linda Lei
> On Mon, 2006-01-23 at 10:52 -0800, Thomas Lumley wrote:
> > On Mon, 23 Jan 2006, Linda Lei wrote:
> >
> > > Thank you guys.
> > > But I tried the commands and I still get:
> > >
> > >> aml1<-aml[aml$group==1,]
> > >> aml1
> > > [1] time   status x
> > > <0 rows> (or 0-length row.names)
> > >> esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)
> > > Error in Surv(aml1$weeks, status) : Time variable is not numeric
> > > In addition: Warning message:
> > > is.na() applied to non-(list or vector) in: is.na(time)
> > >
> > > which still looks confusing. Or are they should be applied in
> s-plus
> > > instead of R?
> >
> > You *still* haven't said where the aml dataset comes from, but as I
> said
> > before, it isn't the same as the one built in to R, so you need to
> load it
> > somehow.  The one in R has columns called "time", "status" and "x";
> you
> > appear to want one with columns "weeks","status", and "group", and
> with
> > "group" being numeric rather than factor.
> >
> >
> >   -thomas
>
>
> I don't have the book with me (it's at home), but I suspect that the
> problem here is that the 'aml' dataset provided at the aforementioned
> web site:
>
>
> http://www.crcpress.com/e_products/downloads/download.asp?cat_no=C4088
>
> which is to be used with the code under discussion, was more than
> likely
> not imported into an R session by Linda.
>
> Since one needs to do a:
>
>   > library(survival)
>
> to utilize the R code examples, that loads that package's 'aml'
> dataset,
> resulting in:
>
>   > aml[aml$group==1,]
> [1] time   status x    
> <0 rows> (or 0-length row.names)
>
> since there is no 'group' column in the built in 'aml' dataset as
> Thomas
> points out.
>
> There is such a structure to the authors' version of the dataset:
>
> > str(read.table("aml.txt", header = TRUE))
> `data.frame': 23 obs. of  3 variables:
>  $ weeks : num  9 13 13 18 23 28 31 34 45 48 ...
>  $ group : num  1 1 1 1 1 1 1 1 1 1 ...
>  $ status: num  1 1 0 1 1 0 1 1 0 1 ...
>
>
> Thus:
>
> >  aml <- read.table("aml.txt", header = TRUE)
>
> > (aml1 <- aml[aml$group==1,])
>    weeks group status
> 1      9     1      1
> 2     13     1      1
> 3     13     1      0
> 4     18     1      1
> 5     23     1      1
> 6     28     1      0
> 7     31     1      1
> 8     34     1      1
> 9     45     1      0
> 10    48     1      1
> 11   161     1      0
>
>
> This bring us to the still remaining error in the authors' survival
> code, which is not fully corrected in the authors' online errata:
>
> > esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)
> Error in Surv(aml1$weeks, status) : object "status" not found
>
>
> Thus, something like one of the following should be used instead:
>
> > esf.fit <- survfit(Surv(aml1$weeks, aml1$status) ~ 1)
>
> > esf.fit <- with(aml1, survfit(Surv(weeks, status) ~ 1))

Hi all,

A quick follow up here. Prof. Kim, one of the authors for the book in
question, replied to my e-mail of earlier today.

There are two issues here:

1. The confounding of the two versions of the 'aml' data set, which has
been identified above. Linda needs to be sure to import the authors'
version of the data set to be able to follow along with the code
examples and exercises in the book.



2. In the code that Linda posted above, in combination with my not
having the book at hand earlier today, there is a single critical line
of code missing that impacts my reply with respect to the final couple
of statements.

The three full lines of code should be:

  aml1 <- aml[aml$group==1,]

  status <- rep(1, 11)

  esf.fit <- survfit(Surv(aml1$weeks,status) ~ 1)


The middle line, creating the local vector 'status', is why the code
that appears corrected in the errata does in fact work and why my
corrections above are not required.

Hope those clarifications help.

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html