Skip to content

Question about tied time calculation in Cox loss #121

Description

@lict99

# sort data by time-to-event or censoring
time_sorted, idx = torch.sort(time)
log_hz_sorted = log_hz[idx]
event_sorted = event[idx]
time_unique = torch.unique(time_sorted) # time-to-event or censoring without ties
if len(time_unique) == len(time_sorted):

Hi,

Thank you for this awesome package! 🙌

I'm not a professional statistician, but while using the loss of CoxPH model I came across something that confused me about the calculation of tied times.

As I understand it, tied times occur when two or more events happen at exactly the same time. Based on that, I rewrote a small snippet to identify tied times:

time_sorted, idx = torch.sort(time) 
log_hz_sorted = log_hz[idx] 
event_sorted = event[idx]  # assume event is a bool tensor
time_to_event = time_sorted[event_sorted]

# only consider times with events when calculating tied times
time_to_event_unique = torch.unique(time_to_event)  

if len(time_to_event_unique) == len(time_to_event):
    # Cox log partial likelihood
else:
    # Breslow or Efron

Am I missing something here about how tied times should be detected or handled?

Thanks again for your work on this project!

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions