Skip to content

Commit d2e10bb

Browse files
committed
Merge pull request #131 from CamDavidsonPilon/cindex_tie_fix
Math was not entirely correct in C-index
2 parents 4d951e2 + f79e5a2 commit d2e10bb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lifelines/_utils/_cindex.f90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ function concordance_index (event_times, predictions, event_observed, rows) resu
3737
event_b = event_observed(b)
3838

3939
! Check if it's a valid comparison
40-
if (event_a == 1 .and. event_b == 1) then
41-
! Two events can always be compared
40+
if (time_a == time_b) then
41+
! Ties are not informative
42+
valid_pair = .false.
43+
else if (event_a == 1 .and. event_b == 1) then
44+
! Two events which are not tied are informative
4245
valid_pair = .true.
4346
else if (event_a == 1 .and. time_a < time_b) then
4447
! If b is censored, then a must have event first
@@ -47,7 +50,7 @@ function concordance_index (event_times, predictions, event_observed, rows) resu
4750
! If a is censored, then b must have event first
4851
valid_pair = .true.
4952
else
50-
! Not valid to compare this pair
53+
! Not an informative pair
5154
valid_pair = .false.
5255
end if
5356

lifelines/_utils/cindex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ def concordance_index(event_times, predicted_event_times, event_observed):
55
"""
66
def valid_comparison(time_a, time_b, event_a, event_b):
77
"""True if times can be compared."""
8-
if event_a and event_b:
8+
if time_a == time_b:
9+
# Ties are not informative
10+
return False
11+
elif event_a and event_b:
912
return True
1013
elif event_a and time_a < time_b:
1114
return True

lifelines/tests/test_estimation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def test_print_summary(self):
479479
---
480480
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
481481
482-
Concordance = 0.642""".strip().split()
482+
Concordance = 0.644""".strip().split()
483483
for i in [0, 1, 2, -2, -1]:
484484
assert output[i] == expected[i]
485485
finally:

0 commit comments

Comments
 (0)