# Handling ties in Cox regression using Peto-Breslow method, is the derivative of the log likelihood correct here?

I am trying to implement Cox proportional hazard model in Python. Although, I know how to calculate the derivates of the Log likelihood, in the case of ties the likelihood function is modified. So I have two queries$$l'(B) = \sum_j \delta_j * [s_j - d_j * \frac{\sum_{k\in R(Tj)} x_k e^{x_k*B}}{\sum_{k\in R(Tj)} e^{x_k*B}}]$$

where s_j is the sum of covariates

Is this log likelihood derivative wrt B correct for Peto-Breslow handling of ties?

Can someone explain me the Efron method and how its Likelihood function looks like? Also its two derivatives.

Section 5.1 of the main R survival vignette explains the handling of ties in Cox models. The problem with tied event times is illustrated by the denominator in your formula:

$$\sum_{k\in R(Tj)} e^{x_k*B},$$

which is the summed estimated risks of all those at risk at time $$T_j$$. With ties, it's not clear which individuals to include in that at-risk group for each of the events at that time. The vignette explains:

The Breslow approximation ... in essence ignores the ties. If two subjects A and B died on day 100, say, the partial likelihood will have separate terms for the two deaths. Subject A will be at risk for the death that happened to B, and B will be at risk for the death that happened to A. In life this is not technically possible of course: whoever died first will not be at risk for the second death.

So the Breslow approximation just solves the standard partial-likelihood score function that you display. It ignores the technical impossibility of all individuals with an event at $$T_j$$ being in the risk set for all those events.

The Efron approximation instead uses an average of the possible denominators in your formula. The vignette starts with the case of two cases with the same event time, and expands from there:

the Efron approximation is to use the average of the two [possible denominators] as the denominator term. In the software this is easily done by using temporary case weights: if there were $$k$$ tied events then one of the denominators gives each of those $$k$$ subjects a weight of 1, then next gives each a weight of $$(k − 1)/k$$, then next a weight of $$(k −2)/k$$, etc.

This page describes how to incorporate weights into the partial likelihood for a Cox model. To check your work, I think that the Python lifelines package uses the Efron method as the default for handling ties.