Survival Analysis¶
Kaplan-Meier estimation, log-rank test (G-rho family), Cox proportional hazards (CPU), and discrete-time survival models (GPU-accelerated).
Survival analysis.
- Public API:
kaplan_meier(time, event, …) -> KMSolution survdiff(time, event, group, …) -> LogRankSolution coxph(time, event, X, …) -> CoxSolution # CPU only discrete_time(time, event, X, …) -> DiscreteTimeSolution # GPU accelerated
- pystatistics.survival.coxph(time, event, X, *, strata=None, ties='efron', tol=1e-09, max_iter=20)[source]¶
Cox proportional hazards model.
CPU only — no backend parameter. Matches R’s survival::coxph().
- Parameters:
time (array-like) – Time to event or censoring.
event (array-like) – Event indicator (1=event, 0=censored).
X (array-like) – Covariate matrix (n, p). No intercept — Cox model has no intercept.
strata (array-like or None) – Strata labels for stratified Cox (not yet implemented).
ties (str) – Method for handling tied event times: “efron” (default) or “breslow”.
tol (float) – Convergence tolerance for Newton-Raphson.
max_iter (int) – Maximum Newton-Raphson iterations.
- Return type:
- pystatistics.survival.discrete_time(time, event, X, *, intervals=None, backend='auto')[source]¶
Discrete-time survival via person-period logistic regression.
GPU-accelerated — delegates to regression.fit(family=’binomial’).
- Parameters:
time (array-like) – Time to event or censoring.
event (array-like) – Event indicator (1=event, 0=censored).
X (array-like) – Covariate matrix (n, p). No intercept — interval dummies serve as the intercept.
intervals (array-like or None) – Time interval boundaries. If None, uses unique event times.
backend (str) – Backend for logistic regression: “auto”, “cpu”, or “gpu”. “auto” selects GPU if available, else CPU.
- Return type:
- pystatistics.survival.kaplan_meier(time, event, *, strata=None, conf_level=0.95, conf_type='log')[source]¶
Kaplan-Meier survival curve estimation.
Matches R’s survival::survfit(Surv(time, event) ~ 1).
- Parameters:
time (array-like) – Time to event or censoring.
event (array-like) – Event indicator (1=event, 0=censored).
strata (array-like or None) – Strata labels for stratified KM (not yet implemented).
conf_level (float) – Confidence level for CI (default 0.95).
conf_type (str) – CI transformation: “log” (R default), “plain”, “log-log”.
- Return type:
- pystatistics.survival.survdiff(time, event, group, *, rho=0.0)[source]¶
Log-rank test (and G-rho family).
Matches R’s survival::survdiff().
- Parameters:
time (array-like) – Time to event or censoring.
event (array-like) – Event indicator (1=event, 0=censored).
group (array-like) – Group labels (e.g. treatment vs control).
rho (float) – G-rho weight parameter. rho=0 (default) gives the standard log-rank test. rho=1 gives Peto & Peto / Gehan-Wilcoxon.
- Return type:
- class pystatistics.survival.CoxSolution(_result)[source]¶
Bases:
objectCox proportional hazards solution.
Properties mirror R’s coxph() output.
- Parameters:
_result (Result[CoxParams])
- property coefficients¶
- property hazard_ratios¶
- property standard_errors¶
- property z_statistics¶
- property p_values¶
- property loglik¶
- property timing¶
- class pystatistics.survival.DiscreteTimeSolution(_result)[source]¶
Bases:
objectDiscrete-time survival model solution.
Properties mirror the logistic regression on person-period data.
- Parameters:
_result (Result[DiscreteTimeParams])
- property coefficients¶
- property standard_errors¶
- property z_statistics¶
- property p_values¶
- property hazard_ratios¶
- property baseline_hazard¶
- property interval_labels¶
- property timing¶
- class pystatistics.survival.KMSolution(_result)[source]¶
Bases:
objectKaplan-Meier survival curve solution.
Properties mirror R’s survfit() output.
- Parameters:
_result (Result[KMParams])
- property time¶
Unique event times.
- property survival¶
S(t) at each event time.
- property n_risk¶
Number at risk just before each event time.
- property n_events¶
Number of events at each event time.
- property n_censored¶
Number censored in each interval.
- property se¶
Greenwood standard error of S(t).
- property ci_lower¶
Lower confidence bound for S(t).
- property ci_upper¶
Upper confidence bound for S(t).
- property timing¶