[R] survival survfit with newdata

David Winsemius dwinsemius at comcast.net
Thu May 17 06:52:55 CEST 2012


On May 16, 2012, at 5:08 PM, Damjan Krstajic wrote:

>
> Dear all,
>
> I am confused with the behaviour of survfit with newdata option.

Yes. It has the same behavior as any other newdata/predict from  
regression. You need to supply a dataframe with the same names as in  
the original formula. Doesn't look as though that strategy is being  
followed. The name of the column needs to be 'trainX' since that was  
what was its name on the RHS of hte formula,  and you may want to  
specify times. If you fail to follow those rules, the function falls  
back on offering estimates from the original data.

>
> I am using the latest version R-2-15-0. In the simple example below  
> I am building a coxph model on 90 patients and trying to predict 10  
> patients. Unfortunately the survival curve at the end is for 90  
> patients.

As is proper with a malformed newdata argument.

> Could somebody please from the survival package confirm that this  
> behaviour is as expected or not - because I cannot find a way of  
> using 'newdata' with really new data. Thanks in advance. DK
>
>> x<-matrix(rnorm(100*20),100,20)
>
>>
> time<-runif(100,min=0,max=7)
>
>>
> status<-sample(c(0,1), 100, replace = TRUE)
>> trainX<-x[11:100,]
>>
> trainTime<-time[11:100]
>>
> trainStatus<-status[11:100]
>>
> testX<-x[1:10,]
>> coxph.model<-
> coxph(Surv(trainTime,trainStatus)~ trainX)
>> sfit<- survfit(coxph.model,newdata=data.frame(testX))
>
>>
> dim(sfit$surv)
>
> [1] 90 90
>
>
> 		 	   		
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list