Skip to content

Commit 2d3295e

Browse files
committed
Correct horizon-specific competing risks
1 parent f16a753 commit 2d3295e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎src/rtichoke/calibration/calibration.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,15 +1059,20 @@ def _apply_heuristics_and_censoring(
10591059

10601060

10611061
def _prepare_adjusted_event_data(
1062-
df: pl.DataFrame, competing_heuristic: str
1062+
df: pl.DataFrame, horizon: float, competing_heuristic: str
10631063
) -> pl.DataFrame:
10641064
"""Prepare event histories for Aalen-Johansen estimation."""
10651065
event_data = df
10661066
if competing_heuristic == "excluded":
1067-
event_data = event_data.filter(pl.col("real") != 2)
1067+
event_data = event_data.filter(
1068+
~((pl.col("real") == 2) & (pl.col("time") <= horizon))
1069+
)
10681070
elif competing_heuristic == "adjusted_as_composite":
10691071
event_data = event_data.with_columns(
1070-
pl.when(pl.col("real") == 2).then(1).otherwise(pl.col("real")).alias("real")
1072+
pl.when((pl.col("real") == 2) & (pl.col("time") <= horizon))
1073+
.then(1)
1074+
.otherwise(pl.col("real"))
1075+
.alias("real")
10711076
)
10721077
return event_data
10731078

@@ -1188,7 +1193,9 @@ def _create_calibration_curve_list_times(
11881193
continue
11891194

11901195
if censoring_heuristic == "adjusted":
1191-
df_adj = _prepare_adjusted_event_data(initial_df, competing_heuristic)
1196+
df_adj = _prepare_adjusted_event_data(
1197+
initial_df, horizon, competing_heuristic
1198+
)
11921199
if df_adj.height == 0:
11931200
continue
11941201

0 commit comments

Comments
 (0)