Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Conduct Kaplan-Meier, Cox regression, and time-to-event analyses
.claude/skills/brycewang-stanford-survival-analysis-guide/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 48% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 22% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 111% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 143% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 30% | 0% |
A skill for conducting time-to-event analyses including Kaplan-Meier estimation, log-rank tests, and Cox proportional hazards regression. Covers censoring concepts, assumption checking, and reporting standards for clinical and social science research.
Survival analysis studies the time until an event of interest occurs. Despite the name, the "event" need not be death -- it can be any well-defined transition:
Medical: Time to disease recurrence, death, or recovery
Engineering: Time to equipment failure
Social: Time to job termination, divorce, or graduation
Business: Time to customer churn or first purchase
Ecology: Time to species extinction in a habitatRight censoring (most common):
The event has not occurred by the end of the study period.
Example: Patient is still alive at study end.
The survival time is "at least T" -- we know T but not the true event time.
Left censoring:
The event occurred before the observation period began.
Example: HIV infection detected, but seroconversion happened before testing.
Interval censoring:
The event occurred between two observation times.
Example: A patient tests negative at visit 3 and positive at visit 4.pythonimport numpy as np def kaplan_meier(times: list[float], events: list[int]) -> dict: """ Compute Kaplan-Meier survival estimates. Args: times: Observed times (event or censoring time) events: Event indicator (1 = event occurred, 0 = censored) Returns: Dict with time points and survival probabilities """ data = sorted(zip(times, events), key=lambda x: x[0]) n = len(data) unique_event_times = sorted(set(t for t, e in data if e == 1)) survival = 1.0 results = {"time": [0], "survival": [1.0]} at_risk = n idx = 0 for t_event in unique_event_times: # Count censored before this event time while idx < n and data[idx][0] < t_event: if data[idx][1] == 0: at_risk -= 1 idx += 1 # Count events at this time d = sum(1 for t, e in data if t == t_event and e == 1) c = sum(1 for t, e in data if t == t_event and e == 0) survival *= (at_risk - d) / at_risk results["time"].append(t_event) results["survival"].append(survival) at_risk -= (d + c) idx = max(idx, sum(1 for t, _ in data if t <= t_event)) return results
pythonfrom lifelines import KaplanMeierFitter kmf = KaplanMeierFitter() kmf.fit(durations=time_column, event_observed=event_column, label="Overall") # Plot the survival curve kmf.plot_survival_function() # Median survival time print(f"Median survival: {kmf.median_survival_time_}") # Survival probability at specific time print(f"5-year survival: {kmf.predict(5.0):.3f}")
pythonfrom lifelines.statistics import logrank_test results = logrank_test( durations_A=group_a_times, durations_B=group_b_times, event_observed_A=group_a_events, event_observed_B=group_b_events ) print(f"Test statistic: {results.test_statistic:.3f}") print(f"p-value: {results.p_value:.4f}")
The log-rank test is the standard method for comparing two or more survival curves. It tests the null hypothesis that the survival functions are identical. It is most powerful when hazards are proportional (consistent relative risk over time).
pythonfrom lifelines import CoxPHFitter import pandas as pd cph = CoxPHFitter() cph.fit( df, duration_col="time", event_col="event", formula="age + treatment + stage" ) cph.print_summary() # Hazard ratios print(cph.summary[["exp(coef)", "exp(coef) lower 95%", "exp(coef) upper 95%", "p"]])
Hazard Ratio (HR) = exp(coefficient)
HR = 1.0 No effect
HR > 1.0 Increased hazard (worse survival)
HR < 1.0 Decreased hazard (better survival)
Example output:
treatment: HR = 0.65, 95% CI [0.48, 0.88], p = 0.005
Interpretation: Treatment group has 35% lower hazard of the event
compared to the control group.python# Schoenfeld residuals test cph.check_assumptions(df, p_value_threshold=0.05, show_plots=True)
If the proportional hazards assumption is violated, consider: stratified Cox models, time-varying covariates, or accelerated failure time (AFT) models as alternatives.
1. Report number of events and total person-time at risk
2. Present Kaplan-Meier curves with number-at-risk tables
3. Report median survival with 95% confidence intervals
4. Report hazard ratios with 95% CIs and p-values
5. State which covariates were included in adjusted models
6. Report proportional hazards assumption test results
7. Specify the handling of tied event times (Efron, Breslow)
8. Note any competing risks and how they were handled| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-02 | pass→pass | 19,912 | 17,251 | -13% | 1 | 1 | 0% | 4,083 | 4,991 | +22% | 0 | 0 | — |
case-01 | fail→pass | 22,757 | 31,518 | +38% | 1 | 1 | 0% | 3,350 | 4,959 | +48% | 0 | 0 | — |
case-03 | fail→fail | 7,570 | 4,862 | -36% | 1 | 1 | 0% | 1,589 | 2,477 | +56% | 0 | 0 | — |
case-04 | pass→pass | 5,477 | 4,703 | -14% | 1 | 1 | 0% | 1,108 | 2,340 | +111% | 0 | 0 | — |
case-05 | pass→pass | 6,454 | 6,790 | +5% | 1 | 1 | 0% | 1,082 | 2,627 | +143% | 0 | 0 | — |
case-06 | pass→pass | 10,323 | 5,600 | -46% | 1 | 1 | 0% | 1,877 | 2,448 | +30% | 0 | 0 | — |
case-07 | pass→pass | 9,463 | 8,559 | -10% | 1 | 1 | 0% | 1,753 | 2,963 | +69% | 0 | 0 | — |
case-08 | pass→pass | 9,429 | 9,098 | -4% | 1 | 1 | 0% | 1,560 | 2,956 | +89% | 0 | 0 | — |
case-09 | pass→pass | 6,909 | 4,502 | -35% | 1 | 1 | 0% | 1,243 | 2,159 | +74% | 0 | 0 | — |
case-10 | pass→pass | 10,342 | 11,289 | +9% | 1 | 1 | 0% | 1,798 | 3,353 | +86% | 0 | 0 | — |
case-11 | pass→pass | 5,464 | 6,451 | +18% | 1 | 1 | 0% | 965 | 2,410 | +150% | 0 | 0 | — |
case-12 | pass→pass | 4,522 | 3,982 | -12% | 1 | 1 | 0% | 765 | 2,051 | +168% | 0 | 0 | — |
case-13 | pass→pass | 5,422 | 3,436 | -37% | 1 | 1 | 0% | 984 | 1,989 | +102% | 0 | 0 | — |
case-14 | pass→pass | 15,353 | 14,877 | -3% | 1 | 1 | 0% | 2,458 | 3,901 | +59% | 0 | 0 | — |
case-15 | pass→pass | 7,489 | 5,157 | -31% | 1 | 1 | 0% | 1,266 | 2,249 | +78% | 0 | 0 | — |
case-16 | pass→pass | 12,067 | 9,139 | -24% | 1 | 1 | 0% | 1,973 | 2,741 | +39% | 0 | 0 | — |
case-17 | pass→pass | 8,032 | 5,946 | -26% | 1 | 1 | 0% | 1,490 | 2,548 | +71% | 0 | 0 | — |
case-18 | pass→pass | 5,646 | 6,607 | +17% | 1 | 1 | 0% | 899 | 2,448 | +172% | 0 | 0 | — |
case-19 | pass→pass | 4,875 | 5,045 | +3% | 1 | 1 | 0% | 947 | 2,394 | +153% | 0 | 0 | — |
case-20 | pass→pass | 6,347 | 6,693 | +5% | 1 | 1 | 0% | 1,054 | 2,351 | +123% | 0 | 0 | — |
case-21 | pass→pass | 11,184 | 12,039 | +8% | 1 | 1 | 0% | 1,948 | 3,502 | +80% | 0 | 0 | — |
case-22 | pass→pass | 7,501 | 11,292 | +51% | 1 | 1 | 0% | 1,437 | 3,483 | +142% | 0 | 0 | — |
case-23 | pass→pass | 12,642 | 11,352 | -10% | 1 | 1 | 0% | 2,309 | 3,613 | +56% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +4 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.