[R] coxph, survfit and Brier score

Stephen Henderson s.henderson at ucl.ac.uk
Wed Jun 29 13:22:02 CEST 2005


Hello and apologies for a very long question. I thought it better to be
verbose and clear than short and imprecise. I am trying to compute the brier
score comparing true surv object of test data to predictions from train data
(using sbrier in ipred package). I am having trouble getting the right
format for my prediction object I think. I have split the DLBCL dataset and
fit a coxph on a training set then I am trying to get out a prediction using
the survfit function with newdata=test. My code is below. 

>library(survival)
>library(ipred)


>data(DLBCL)
>DLBCL[complete.cases(DLBCL),]->DLBCL
>train<-DLBCL[1:19,]
>test<-DLBCL[20:38,]
>train.surv<-Surv(train$time, train$cens)
>test.surv<-Surv(test$time, test$cens)


>train.mod<-coxph(train.surv~IPI, data=train)
> pred<- survfit(train.mod, newdata=test)

>class(pred)
[1] "survfit.cox" "survfit"

>pred

Call: survfit.coxph(object = train.mod, newdata = test)

       n events median 0.95LCL 0.95UCL
 [1,] 19     10    Inf    27.1     Inf
 [2,] 19     10    Inf     Inf     Inf
 [3,] 19     10    Inf     Inf     Inf
 [4,] 19     10   23.7     4.1     Inf
 [5,] 19     10   23.7     4.1     Inf
 [6,] 19     10    Inf    27.1     Inf
 [7,] 19     10    Inf     Inf     Inf
 [8,] 19     10    Inf     Inf     Inf
 [9,] 19     10    Inf    27.1     Inf
[10,] 19     10    4.1     2.9     Inf
[11,] 19     10    Inf    27.1     Inf
[12,] 19     10    4.1     2.9     Inf
[13,] 19     10    Inf     Inf     Inf
[14,] 19     10   23.7     4.1     Inf
[15,] 19     10    Inf    27.1     Inf
[16,] 19     10    Inf    27.1     Inf
[17,] 19     10    Inf     Inf     Inf
[18,] 19     10    Inf     Inf     Inf
[19,] 19     10    Inf    27.1     Inf


>sbrier(test.surv, pred)
Error in switch(ptype, survfit = { : switch: EXPR must return a length 1
vector

The sbrier function clearly does not recognize the format of this survfit
object "pred". Indeed it seems to have the same variables but does not look
like the object you receive from a normal survfit call e.g. 


>KM <- survfit(train.surv)
>KM
Call: survfit(formula = train.surv)

      n  events  median 0.95LCL 0.95UCL 
   19.0    10.0    71.3    15.5     Inf 

>sbrier(train.surv, KM)
integrated Brier score 
             0.2220228 
attr(,"time")
[1]   2.4 102.4

My question is can I either force survfit(etc..., newdata=x) to return a
useful survfit object for use with sbrier, or alternatively coerce the pred
object above into a survfit object? Or am I missing something ..is there a
reason survfit returns the predicted object in a different format?

PS I realize the fit is not good but just want to get the code to work.

Thank You

Stephen Henderson


**********************************************************************
This email and any files transmitted with it are confidentia...{{dropped}}




More information about the R-help mailing list