0

I am having difficulty making predictions using coxph.

I wish to learn a Cox PH model on in-sample data and then use the parameters derived on out of sample data as follows:

# learn IS params
model.PH <- coxph(Surv(days.IS, outcome.IS) ~ predictor.IS)

# apply IS params to OOS data to make predictions
predictions.raw <- predict(model.PH, newdata = predictor.OS)

# binarise predictions
predictions.OS <- rep(0,length(predictions.raw))    
predictions.OS[which(predictions.raw>0)]<- 1 

# fit survival model
fittedModel <- survdiff(Surv(days.OS, outcome.OS) ~ predictions.OS)

predictor.IS is of dimensionality Y_1 x D, predictor.OS is of dimensionality Y_2 x D

However, this does not work as the number of elements in predictions.OS is Y_1 NOT Y_2.

What am I doing wrong?

  • 3
    This would be easier to answer if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – MrFlick Sep 01 '14 at 19:40
  • The Zelig package is quite useful and very easy to implement for this type of problem. – Brian P Sep 01 '14 at 19:56
  • 1
    This would probably work more cleanly if you passed values to ``coxph using a `data=dfrm` argument and then passed a `newdata` argument to `predict` as a different dataframe with the same column names. I get the sense you are passing matrices that may not have the same column names as a re found in the model. Dimensionality matching is not the only requirement for the predict.coxph function. – IRTFM Sep 02 '14 at 03:15
  • BondedDust - you solved the problem - thank you! It was because I was ignoring the "data=" bits. – Tristan Fletcher Sep 02 '14 at 12:36
  • @BondedDust: Since you effectively solved the OP's problem, I suggest you post an answer so that it can be accepted. :) – Alex A. Dec 17 '14 at 21:49
  • That will only work if the OP is still "listening". – IRTFM Dec 17 '14 at 21:52

1 Answers1

0

This would probably work more cleanly if you passed values to ``coxph using a data=dfrm argument and then passed a newdata argument to predict as a different dataframe with the same column names. I get the sense you are passing matrices that may not have the same column names as a re found in the model. Dimensionality matching is not the only requirement for the predict.coxph function.

IRTFM
  • 258,963
  • 21
  • 364
  • 487