I am a medical oncologist in training with basic stat and R programming skills interested in survival analysis. My question is short but I haven´t been able to find an answer online anywhere.

Is it possible to calculate HR in Cox regression by hand and show it with a simple example? Can someone refer to a book/website where the calculation is carried out by hand from beginning to end?

For example if I were to be interested to find out the HR between males and females in this hypothetical dataset with 10 patients.

Time: 5, 4, 10+, 3+, 8, 9+, 1+, 5, 6+, 3 (+ = censored)
Gender: M, M, F, F, F, F, M, M, F, M

HR=exp(beta), beta obtained from maximum likelihood estimation.You could write out the likelihood, take the log likelihood, differentiate with respect to beta, set to 0 and solve for beta. Likelihood is product of probabilities: Pr[ ith individual dies at tj | a death at tj] etc. Likeihood is independent of baseline hazard

edit: “Can someone refer to a book/website where the calculation is carried out by hand from beginning to end?” - unfortunately not, it would only be done by hand for edification ie by students and in course notes which are unlikely to appear online(?)

That is exactly what I see online and in books, ie only theory without any practical calculation. The theory makes conseptually sense to a “clinician non-mathematician” but I cannot figure out why no one can show it with a practical example since Cox model seems to be everywhere…

it might be that they dont want to encourage people to do the calculation by hand. i remember doing such a thing by hand and was ridiculed by the professor who said: it’s more difficult if the model is more difficult, ie what is the point if things are never this simple? that’s the attitude unfortunately

Terry Therneau shows this for a simple case, either in one of the vignettes to his R survival package or in his book with Grambsch Extending the Cox Model.

unless the example is really simple (even simpler than what you present) youd need to know by heart multiple rules of differentiation, otherwise it would be difficult to follow. Note newton raphson is used for estimating the regression parameters in stats packages

Assuming an exponential distribution for survival times and that the HR is constant (PH assumption), both commonly used assumptions in oncology, then the marginal HR in the Cox regression model can be calculated by dividing the median survival times for males and females. For example, if median survival for males is 4 months and for females 2 months then HR = 4/2 = 0.5 or the corresponding inversion 2/4 = 2.0.

Additional practical considerations and formulas for clinical oncologists are provided here.