Skip to content

Commit

Permalink
Silence AJ warning on tied events
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrisel committed Jul 4, 2024
1 parent ee8af69 commit d90cf4f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/plot_marginal_cumulative_incidence_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ def plot_cumulative_incidence_functions(y, survival_boost=None, aj=None):
ax.set(title=f"Event {event_id}")

if aj is not None:
# Randomly break tied durations, to silence a warning raised by the
# Aalen-Johansen estimator.
rng = np.random.default_rng(0)
jitter = rng.normal(scale=1e-3, size=y.shape[0])
tic = perf_counter()
aj.fit(y["duration"], y["event"], event_of_interest=event_id)
aj.fit(y["duration"] + jitter, y["event"], event_of_interest=event_id)
duration = perf_counter() - tic
print(f"Aalen-Johansen for event {event_id} fit in {duration:.3f} s")
aj.plot(label="Aalen-Johansen", ax=ax)
Expand Down

0 comments on commit d90cf4f

Please sign in to comment.