Skip to content

Simplification: medium-risk numerical dedup batch — AJ increment helper, risk-set convention helper, bootstrap_cb merge, CB transform sharing, Cox TVC wrappers, CopulaModel serialisation #299

Description

@derrynknife

Remaining medium-risk items from the simplification review, grouped:

  1. Aalen-Johansen increment implemented three times: competing_risks/nonparametric/competing_risks.py:245-248, competing_risks/regression/competing_risks_proportional_hazard.py:110-120 (same Competing risks: CIF uses S(t) instead of S(t-); queries before first event wrap to last value; fit_from_df shadows df() #253/Competing risks: default Nelson-Aalen method produces CIFs that exceed 1 #278 comments), gray_test.py:190-205 (loop form). One aalen_johansen_iif(S_km, hazard_increments) helper; Competing risks: default Nelson-Aalen method produces CIFs that exceed 1 #278 was exactly one of these copies going wrong.
  2. Cox at-risk rule (tl < tau) & (x >= tau) hand-rolled in three Python loops (cox_ph.baseline:289-295 — O(K·N), _prepare_exact_tie_data:519-527, diagnostics._risk_set_means:102-105) while vectorised equivalents (at_risk_beta_Z + not_yet_entered) exist in the same file. Minimum: vectorise baseline(); add one documented risk-set-convention helper so the entry-strict/exit-inclusive rule lives in one place. Pinned by the R/lifelines comparison tests.
  3. degradation/_bounds.py bootstrap_cb vs bootstrap_cb_accelerated (~40 lines): same resample→refit→quantile loop; merge with Z=None.
  4. CB transform sharing: parametric.py:1394-1465 and regression/_bounds.py:48-116 implement the same logit-sf / log-rate transforms with different jacobian engines (autograd vs FD — keep both engines, share only the transform functions and align the two-sided output layout).
  5. Cox TVC entry-point quartet (cox_ph.py:955-1132) structurally mirrors TVCFitMixin (tvc_fit.py:42-148); a _post_tvc_fit hook collapses at least the two *_from_df wrappers (Cox's docstrings are worth keeping, which limits the net win).
  6. CopulaModel.to_dict (multivariate/parametric/copula/copula_model.py:89-99) is the only to_dict without stamp_schema, has no from_dict, and writes a "parameterization" tag surpyval.from_dict doesn't recognise — it serialises to something nothing can read. Either register + implement from_dict, or document one-way export.

Each item should land with before/after numerical-equality checks on the relevant suites. (Low-risk simplification items from the same review are being applied directly.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions