|
# 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!
torchsurv/src/torchsurv/loss/cox.py
Lines 209 to 215 in a08e9d1
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:
Am I missing something here about how tied times should be detected or handled?
Thanks again for your work on this project!