Quickstart: Survival Analysis
Use this when your cohort already has duration and event columns.
For endpoint construction through evaluation, use the recommended survival workflow and its runnable synthetic example.
Install
uv add "fyron[survival]"Plot Kaplan-Meier Curves
import pandas as pd
from fyron.survival import check_ph_assumptions, fit_multivariate_cox, plot_kaplan_meier
cohort = pd.DataFrame(
{
"time": [4, 8, 10, 13, 15, 19, 23, 30],
"event": [1, 0, 1, 1, 0, 1, 0, 1],
"risk_group": ["low", "low", "high", "high", "low", "high", "low", "high"],
"age": [58, 61, 73, 69, 54, 77, 63, 71],
}
)
fig, ax = plot_kaplan_meier(
cohort,
duration_col="time",
event_col="event",
group_col="risk_group",
at_risk_counts=["At risk"],
)Fit A Cox Model
cox = fit_multivariate_cox(
cohort,
duration_col="time",
event_col="event",
covariates=["age"],
)
ph = check_ph_assumptions(cox.model, cohort[["time", "event", "age"]])
print(ph.summary)Next Steps
- Read Survival Analysis for RMST, Weibull AFT, Cox forest tables, and proportional hazards diagnostics.
- Use Survival PH Diagnostics Guide for Schoenfeld residual interpretation.