Hi - I've seen a similar issue going on with survfit when using strata in
the model, although I get a different error message from ge.  If it helps
to track down the problem (rather than confusing things further) here is
some code that should reproduce the issue I've seen.  I'm running R 2.15.2,
with survival version 2.36-14 .

Cheers,
Carina

##################

library(survival)

# use aml dataset from survival & create 3 imaginary possible stratas -
strat3 has 3 levels, strat4 has 4 levels, strat5 has 5 levels
aml$strat3<-as.factor(rep(c(1:3),length=nrow(aml)))
aml$strat4<-as.factor(rep(c(1:4),length=nrow(aml)))
aml$strat5<-as.factor(rep(c(1:5),length=nrow(aml)))

# create a counting process format dataset from aml - call this aml2
aml2<-survSplit(aml,cut=c(5,10,50),end="time",start="start",event="status",episode="i",id="indiv")

# create a dataset of 4 'new' observations - call this aml.new
aml.new<-aml[1:4,]
aml.new$time<-c(30,50,70,100)
aml.new$status<-1
aml.new$x[1:4]<-c(rep("Maintained",2),rep("Nonmaintained",2))
aml.new$strat3[1:4]<-"1"
aml.new$strat4[1:4]<-"1"
aml.new$strat5[1:4]<-"1"

# create a counting process format dataset from aml.new - call this aml2.new
aml2.new<-survSplit(aml.new,cut=c(5,10,50),end="time",start="start",event="status",episode="i",id="indiv")

# First a model using no strata - survfit works fine on new dataset
myModel<-coxph(Surv(start, time, status) ~ x,data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

# Now a model using strata = strat4 (which has 4 levels) - survfit again
works fine on new dataset (which has 4 new individuals)
myModel<-coxph(Surv(start, time, status) ~ x+strata(strat4),data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

# Now a model using strata = strat3 (which has 3 levels) - survfit works
here too
myModel<-coxph(Surv(start, time, status) ~ x+strata(strat3),data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

# Now a model using strata = strat5 (which has 5 levels) - survfit now does
not work, with error saying
# Error in survfitcoxph.fit(y, x, wt, x2, risk, newrisk, strata, se.fit,  :
#  'names' attribute [5] must be the same length as the vector [4]
myModel<-coxph(Surv(start, time, status) ~ x+strata(strat5),data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

# Now recreate aml.new but with 3 rather than 4 'new' observations
rm(aml.new)
aml.new<-aml[1:3,]
aml.new$time<-c(30,50,70)
aml.new$status<-1
aml.new$x[1:3]<-c(rep("Maintained",2),rep("Nonmaintained",1))
aml.new$strat3[1:3]<-"1"
aml.new$strat4[1:3]<-"1"
aml.new$strat5[1:3]<-"1"

# create a counting process format dataset from aml.new
aml2.new<-survSplit(aml.new,cut=c(5,10,50),end="time",start="start",event="status",episode="i",id="indiv")


# Survfit on model using strat3 still works
myModel<-coxph(Surv(start, time, status) ~ x+strata(strat3),data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

# But Survfit on model using strat4 doesn't work now
myModel<-coxph(Surv(start, time, status) ~ x+strata(strat4),data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

# Survfit on strat5 model doesn't work either
myModel<-coxph(Surv(start, time, status) ~ x+strata(strat5),data = aml2)
plot(survfit(myModel,aml2.new,id=indiv))

####################





On 19 November 2012 17:01, Terry Therneau <thern...@mayo.edu> wrote:

> I can't reproduce the problem.
>
> Tell us what version of R and what version of the survival package.
> Create a reproducable example.  I don't know if some variables are numeric
> and some are factors, how/where the "surv" object was defined, etc.
>
> Terry Therneau
>
>
>
>
> On 11/17/2012 05:00 AM, r-help-requ...@r-project.org wrote:
>
>> This works ok:
>>
>>  >  cox = coxph(surv ~ bucket*(today + accor + both) + activity, data =
>>> data)
>>> >  fit = survfit(cox, newdata=data[1:100,])
>>>
>> but using strata leads to problems:
>>
>>  >  cox.s = coxph(surv ~  bucket*(today + accor + both) +
>>> strata(activity),
>>> >  data = data)
>>> >  fit.s = survfit(cox.s, newdata=data[1:100,])
>>>
>> Error in model.frame.default(data = data[1:100, ], formula = ~bucket +  :
>>    number of variables != number of variable names
>>
>> Note that the following give rise to the same error:
>>
>>  >  fit.s = survfit(cox.s, newdata=data)
>>>
>> Error in model.frame.default(data = data, formula = ~bucket + today +  :
>>    number of variables != number of variable names
>>
>> but if I use data implicitly, all is working fine:
>>
>>> >  fit.s = survfit(cox.s)
>>>
>> Any idea on how I could solve this?
>>
>> Best, and thank you,
>>
>> ge
>>
>
> ______________________________**________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/**
> posting-guide.html <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
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