This is a basic question to understand how datasets for survival analysis are constructed. I understand the terms in the model, given by this equation: Cox proportional hazards regression model

(P.41, G. Brostrom, "Event History Analysis with R")/

And I understand how to specify a the base-rate hazard function $h_0(t)$, and associate covariates with the covariate term, $e^{x_i\beta}$. Let's assume either the base-rate hazard function is given, or I've estimated it using a Nelson-Aalen Estimator. What I'm missing is how to specify $h(t; x_i)$ from my data. The unit of analysis in the data are individuals with, let's say for simplicity, the time of an event (e.g. death) within the duration of the study, assuming that each individual was present at the study beginning (no left censoring), and died before the end of the study (no right censoring). So each individual generates one and only one event within the duration of the study.

To illustrate, if I look at examples in R, the LHS 'survival object' is generated by Surv(enter, exit, event). In short, how is this computed, and how is it used in computing the regression by the appropriate GLM method?. (Given the formulation, the details about use of partial likelihood appear straightforward in the text.) I presume there's a different answer if time is continuous or discrete.

Just to say why I just don't use the R package functions; I have a non-standard, periodic base-rate hazard function, and I can't use R in the actual code.

  • $\begingroup$ Have you tried looking at the R code? Start R, load the survival library, and type Surv and then coxph: in both cases, without the trailing () so you get the code rather than call the function. I understand that some parts of the survival functionality are provided by compiled functions rather than by R functions, but their source codes are available for download from CRAN. $\endgroup$
    – EdM
    Oct 16, 2014 at 17:30
  • $\begingroup$ Yes, I've tried looking at the R code :) Surv() returns a list of closed-right intervals, marked as either events or censured. Specifically the question then is how such marked intervals are regressed against. $\endgroup$
    – John Mark
    Oct 16, 2014 at 20:44

1 Answer 1


The calculation of partial likelihood in Cox regression is done event-by-event, with only cases still at risk at each event time included; don't know that thinking about this as a GLM necessarily helps. At each event time $t_i$ take the ratio of $e^{x_i\beta}$ (where case i had the event at $t_i$) to the sum of $e^{x_j\beta}$ over all cases j still at risk at that time (in your terminlogy, with exit >= $t_i$). The partial likelihood, which is to be maximized, is then the product of these ratios over all event times. See the Proportional_hazards_model Wikipedia page for details and how to deal with issues like tied times.

In terms of the Surv() object, only exit times for which the event marker is true are used in calculating partial likelihood. Each case for which the event marker is false only contributes to the calculation of partial likelihoods at times up to its exit.

An important advantage is that you don't have to specify the baseline hazard at all. With the assumption of proportional hazards, the baseline hazard cancels out.

If you want to impose a "non-standard, periodic base-rate hazard function" you can do that in R, with the survreg() function in the survival package; an example in the help page for survreg.distributions shows how to specify an arbitrary baseline hazard function. If for some reason you still need to code this yourself outside of R, look more deeply into the R source code; download the source for the survival package and look, for example, at the C code for coxfit6.c, which does much of the heavy lifting for regressions performed with coxph().


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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