Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a860c698f | |||
| 6e6c5bb81b |
@@ -34,6 +34,16 @@ COHORT_SCENARIOS = {
|
||||
}
|
||||
# Reasons that a result still to arrive could lift.
|
||||
AWAITING = {"unreported_biopsy", "no_index_result"}
|
||||
# Clinical categories, not execution order: a candidate may belong to several stages.
|
||||
REASON_STAGE = {
|
||||
"hysterectomy": "eligibility", "under_18": "eligibility",
|
||||
"no_birth_date": "eligibility", "died_by_index": "eligibility",
|
||||
"prior_outcome": "history", "outcome_by_index": "history",
|
||||
"cancer_history": "history", "prior_treatment": "history",
|
||||
"outcome_before_index": "history", "no_pretreatment_biopsy": "history",
|
||||
"no_referral": "index", "no_cotest": "index",
|
||||
"no_index_result": "index", "unreported_biopsy": "index",
|
||||
}
|
||||
|
||||
|
||||
def attrition(cohort: str, rows: pd.DataFrame, people: int, as_of: date) -> dict:
|
||||
@@ -46,6 +56,7 @@ def attrition(cohort: str, rows: pd.DataFrame, people: int, as_of: date) -> dict
|
||||
excluded = rows[rows["criterion"].notna()]
|
||||
reasons = excluded.groupby(key, dropna=False)["criterion"].agg(set)
|
||||
pending = int(sum(found <= AWAITING for found in reasons))
|
||||
stages = excluded.assign(stage=excluded["criterion"].map(REASON_STAGE).fillna("unknown"))
|
||||
return {
|
||||
"cohort": cohort,
|
||||
"scenario": COHORT_SCENARIOS[cohort],
|
||||
@@ -60,6 +71,13 @@ def attrition(cohort: str, rows: pd.DataFrame, people: int, as_of: date) -> dict
|
||||
str(reason): int(count)
|
||||
for reason, count in excluded["criterion"].value_counts().sort_index().items()
|
||||
},
|
||||
"by_stage": {
|
||||
str(stage): len(group[key].drop_duplicates())
|
||||
for stage, group in stages.groupby("stage", sort=True)
|
||||
},
|
||||
"stage_by_reason": {str(reason): REASON_STAGE.get(str(reason), "unknown")
|
||||
for reason in sorted(excluded["criterion"].unique())},
|
||||
"stage_counts_overlap": True,
|
||||
}
|
||||
|
||||
|
||||
|
||||
+20
-1
@@ -487,7 +487,7 @@ def interpretability(spec: Spec, model: IntervalSurvival, data: dict) -> dict:
|
||||
for n, m in masks.items() if n not in drawn] # fmt: skip
|
||||
combinations = spec._combinations(train).value_counts().reset_index(name="members")
|
||||
survival = model.survival(combinations.replace(UNKNOWN, None))
|
||||
return {
|
||||
report = {
|
||||
"model": spec.name,
|
||||
"kind": "curves",
|
||||
"curves": curves,
|
||||
@@ -509,6 +509,25 @@ def interpretability(spec: Spec, model: IntervalSurvival, data: dict) -> dict:
|
||||
"min_fallecidos_escenario": MIN_SCENARIO_EVENTS,
|
||||
**risk_factor_report(spec, model, members),
|
||||
}
|
||||
if spec.cohort.startswith("cacu_"):
|
||||
for curve in report["curves"]:
|
||||
method = ("greenwood_log_log" if curve["name"].startswith("Kaplan-Meier")
|
||||
else "delta_method")
|
||||
curve["interval"] = {"available": True, "level": 0.95, "method": method}
|
||||
report["predicted"]["interval"] = {
|
||||
"available": True, "level": 0.95, "method": "bootstrap_percentile"}
|
||||
for combination in report["combinations"]:
|
||||
combination["interval"] = {"available": False, "level": None, "method": None}
|
||||
for scenario in report["escenarios"]:
|
||||
scenario["km"]["interval"] = {
|
||||
"available": True, "level": 0.95, "method": "greenwood_log_log"}
|
||||
for name in ("weibull", "weibull_fractional"):
|
||||
scenario[name]["interval"] = {"available": False, "level": None, "method": None}
|
||||
scenario["points"]["COMB"]["interval"] = {
|
||||
"available": True, "level": 0.95, "method": "bootstrap_percentile"}
|
||||
for scenario in report["escenarios_sin_curvas"]:
|
||||
scenario["reason"] = "insufficient_deaths"
|
||||
return report
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- risk factors
|
||||
|
||||
@@ -29,3 +29,6 @@ def test_a_candidate_with_two_reasons_is_excluded_once():
|
||||
assert found["by_reason"] == {
|
||||
"hysterectomy": 1, "no_index_result": 2, "prior_outcome": 1, "under_18": 1,
|
||||
} # fmt: skip
|
||||
assert found["by_stage"] == {"eligibility": 1, "history": 1, "index": 2}
|
||||
assert found["stage_by_reason"]["no_index_result"] == "index"
|
||||
assert found["stage_counts_overlap"] is True
|
||||
|
||||
Reference in New Issue
Block a user