I have built a cox model in R using the coxph function in the survival package, and now I need to replicate the model in SQL for scoring. From my understanding, the model has the form described on the bottom of page 2 of this document, http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf, which gives it semi-parametric flexibility. Since there is an unspecified alpha term, I cannot just take the coefficients and use the model like a typical linear model or generalized linear model (and exponentiate). There are ways to estimate this alpha term, and I believe this added term to the hazard is needed to specify the complete model. If this is the case, how do I get my hands on this alpha term?


If you only need relative scoring you can just use $X\hat{\beta}$ from the Cox model, otherwise you need to consider the underlying survival curve and state what you want to predict (probability, mean, quantile, etc.). The R rms package facilitates much of this by providing code generators Function, Quantile, Mean and for R functions created by Function (these express $X\hat{\beta}$) you can translate these to other languages. Built-in translators in rms are sascode and perlcode. All this handles nonlinearities using splines, and interactions. By the way how you built the model is crucial, and needs to be very well thought out before going to any trouble to translate it for export. Nonlinearity is the most frequently violated assumption that matters the most. Non-proportional hazards is another issue. And make sure that all continuous predictors are kept continuous in the model.

  • $\begingroup$ Thanks for your response, Frank. Can you explain a bit more in-depth about what you mean by "consider the underlying survival curve and what you want to predict"? I want to predict the survival probabilities of new observations. Is there a way to do this that you know of? $\endgroup$ – Melissa Jul 30 '14 at 16:41
  • $\begingroup$ If you use $\LaTeX$ you can run latex(cph result) to see the entire model statement including a table of underlying survival probabilities you can plug in. There are like a series of intercepts in the model. You would have to program that part; the Function function does the more complex linear predictor part of the model. If you want survival estimates at a single fixed time horizon then reading that off the $\LaTeX$ output and programming it is very easy. Be cognizant of the cph function time.inc argument. $\endgroup$ – Frank Harrell Jul 30 '14 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.