On Jul 21, 2009, at 7:23 PM, Joseph Magagnoli wrote:

Hi all,
I am getting an error in my code and I don't know what the problem is.
I am using R 2.9 on ubuntu.   my code is as follows:

## Libraries ##
library(survival)
library(foreign)

## reading data ##

data<-read.dta("http://psfaculty.ucdavis.edu/bsjjones/cabinet.dta";)
head(data)
attach(data)


fit1<-survfit(Surv(durat,censor))
and I get the following error
fit1<-survfit(Surv(durat,censor))
Error in survfit(Surv(durat, censor)) :
 Survfit requires a formula or a coxph fit as the first argument
any help is greatly appreciated
Joe


Try:

  fit1 <- survfit(Surv(durat, censor) ~ 1, data = data)

See ?survfit and note in the description of 'formula':

  For a single survival curve the right hand side should be ~ 1.

I would also avoid using attach() as it can create subsequent problems, which is why there is the 'data' argument to most R functions that take a formula argument.

HTH,

Marc Schwartz

______________________________________________
R-help@r-project.org 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.

Reply via email to