For the complete documentation index, see llms.txt. This page is also available as Markdown.

Cox survival models

Assess associations between clinical variables and survival using Cox models, including covariate-adjusted effects, interactions, and adjusted survival curves.

Assess associations between clinical variables and survival using Cox models, including covariate-adjusted effects, interactions, and adjusted survival curves.

Prognostic subgroup survival

Description

Analysis summary

Displays the prognostic impact of each subgroup level on survival using hazard ratios and confidence intervals estimated from Cox proportional hazards models fit across the cohort. For each subgroup variable, non-reference levels are compared against a designated reference level (hazard ratio = 1). The tool can also generate covariate-adjusted survival curves by group.

Computation

Fits Cox proportional-hazards models via the lifelines library, on one row per patient — rows are deduplicated to one per patient and patients missing any model input are dropped. Multivariate (default): one model with all subgroup variables plus adjustment covariates; univariate: one model per subgroup variable, each including the covariates. Each categorical subgroup level yields a hazard ratio against its variable's reference level, with a 95% confidence interval and p-value; a continuous subgroup variable yields a per-unit hazard ratio. The reference level's row is hazard ratio 1 by definition, and the adjustment variables get estimate rows too (hidden by default). Subgroup levels with fewer than 5 patients or 3 events are excluded from the display. Setting the analysis's plot to kaplan_meier instead fits one Cox model in which the first subgroup variable defines the displayed groups (the remaining subgroup variables and the adjustment covariates adjust the model) and predicts each group's survival curve, holding all other covariates at their mean (numeric) or mode (categorical): confidence bands come from coefficient uncertainty via the delta method on the log cumulative hazard, over a horizon trimmed to the configured percentile of observed follow-up.

When to use

Use to assess how clinical features (stage, gender, etc.) influence outcome on their own — the 'prognostic effect(s) of one or more clinical variables on survival' — and for covariate-adjusted survival curves when the user asks to 'adjust for' covariates in a KM-style plot. For the effect of a treatment or biomarker compared across subgroups, use the interaction mode; for unadjusted Kaplan–Meier curves use kaplan_meier_analysis.

Caveats

Cox models assume proportional hazards, and non-convergent runs raise an error rather than outputting approximations. Listwise deletion across covariates may substantially reduce the analyzed sample relative to the initial cohort. Additionally, confidence bands on adjusted survival curves reflect coefficient uncertainty only—excluding baseline hazard variance—so intervals may underestimate true uncertainty at later follow-up times when numbers at risk are small.

lifelines — the survival-analysis Python library this analysis fits its Cox models with. Documentation: https://lifelines.readthedocs.io/en/latest/ — paper: Davidson-Pilon, C. (2019). lifelines: survival analysis in Python. Journal of Open Source Software, 4(40), 1317. https://doi.org/10.21105/joss.01317.

Example questions

example questions
  • forest — multivariate prognostic subgroup effects (no effect_var)

  • forest — univariate prognostic subgroup effects (one model per variable)

  • Cox-adjusted survival curves — KM-style curves controlling for covariates

Input columns

input columns
column
type
required
description

patient_id

categorical, any

required

Unique patient identifier — one row per patient.

time

numeric

required

Survival duration in years (aliased from the raw column in SQL, e.g. overall_survival AS time or progression_free_survival AS time).

event

boolean, numeric

required

Event indicator (boolean or 0/1; True/1 = event occurred). Aliased in SQL, e.g. os_event AS event or pfs_event AS event.

<stratify_by columns>

categorical

required

One or more categorical columns used as subgroup variables (e.g. 'gender', 'stage'). Listed in the stratify_by parameter.

<adjust_vars columns>

numeric, categorical

optional

Zero or more columns to include as covariates in the Cox model (e.g. 'age'). Listed in the adjust_vars parameter. Their rows are hidden by default; set show_ad…

Visualizations

  • forest How to read: One row per subgroup level (or per unit for continuous variables): the point is the hazard ratio, the whiskers its 95% confidence interval, and the dashed reference line sits at 1 (no effect). Reference-level rows sit at hazard ratio 1 with no estimate — hide them with show_reference; adjustment-variable rows are hidden unless show_adjust_vars. Rows are sorted by hazard ratio within each variable group by default (sort_by); the x-axis is log-scaled by default, and rows with non-positive estimates are dropped on that scale. Hover gives the p-value; subgroup levels with fewer than 5 patients or 3 events are excluded.

  • kaplan_meier How to read: Cox-adjusted survival curves: one curve per level of the displayed group variable, each adjusted for the model's other covariates held at their mean (numeric) or mode (categorical). Shaded bands are confidence intervals (toggle with show_ci). The x-axis is time in the selected unit, ending at the configured follow-up percentile; the y-axis is the outcome label (e.g. Overall Survival). These are model-adjusted curves, not Kaplan–Meier estimates of the raw data.

Example analysis 1

Name — Overall Survival Subgroup Effects by Gender and Stage — Bladder Cancer (TCGA)

Analysis parameters

analysis_name, analysis_params, viz_params

Visualization — forest

Overall Survival Subgroup Effects by Gender and Stage — Bladder Cancer (TCGA)

Output table

statistical_tests (6 rows)
label
effect
ci_low
ci_high
p_value
n
n_events
subgroup_variable
subgroup_level
model_formula
model_variable

Effect for Sex = female

1.0

1.0

1.0

107

51

gender

female

gender + condition_stage

multivariate

Effect for Sex = male

0.8301

0.5989

1.151

0.2635

298

126

gender

male

gender + condition_stage

multivariate

Effect for Condition stage = I

1.0

1.0

1.0

2

0

condition_stage

I

gender + condition_stage

multivariate

Effect for Condition stage = II

1714000.0

0.0

0.9936

130

35

condition_stage

II

gender + condition_stage

multivariate

Effect for Condition stage = III

2762000.0

0.0

0.9934

140

57

condition_stage

III

gender + condition_stage

multivariate

Effect for Condition stage = IV

4982000.0

0.0

0.9931

133

85

condition_stage

IV

gender + condition_stage

multivariate

Example analysis 2

Name — Cox-Adjusted Overall Survival by Gender (Adjusted for Age and Smoking Status)

Analysis parameters

analysis_name, analysis_params, viz_params

Visualization — kaplan_meier

Cox-Adjusted Overall Survival by Gender (Adjusted for Age and Smoking Status)

Output table

statistical_tests (5 rows)
term
coef
exp(coef)
se(coef)
coef lower 95%
coef upper 95%
exp(coef) lower 95%
exp(coef) upper 95%
cmp to
z
p
-log2(p)

gender[T.male]

0.07944

1.083

0.06521

-0.04838

0.2073

0.9528

1.23

0.0

1.218

0.2232

2.164

age

0.02526

1.026

0.002919

0.01954

0.03098

1.02

1.031

0.0

8.653

5.036e-18

57.46

smoking_status[T.tobacco_former_smoker]

0.3247

1.384

0.2979

-0.2593

0.9086

0.7716

2.481

0.0

1.09

0.2758

1.858

smoking_status[T.tobacco_non_smoker]

0.4634

1.589

0.2949

-0.1147

1.041

0.8916

2.833

0.0

1.571

0.1162

3.106

smoking_status[T.tobacco_smoker]

0.5271

1.694

0.2927

-0.04652

1.101

0.9545

3.006

0.0

1.801

0.0717

3.802

Interaction (effect of a variable across subgroups)

Description

Analysis summary

Quantifies how the effect of one variable (e.g. a treatment, a biomarker) on survival changes across subgroups defined by other variables (e.g. stage, gender): one hazard ratio per subgroup level — useful for finding subgroups where the treatment helps more or less than overall.

Computation

Fits a Cox model with the effect variable, the subgroup variables, and their interaction terms, via the lifelines library; adjustment covariates join the model as pure covariates with no estimate rows. The effect variable must be binary or two-level categorical; its two levels are ordered alphabetically and the model contrasts the second against the first. Each subgroup level shows the hazard ratio of the effect variable within that subgroup: the reference subgroup shows the model's base effect, the other levels add their interaction term, with the standard error combining the base and interaction coefficients' variance and covariance. An 'Overall' row gives the effect across the whole cohort. Multivariate (one model with all subgroup variables) vs univariate (one model per subgroup variable) behaves as in prognostic mode, and subgroup levels with fewer than 5 patients or 3 events are excluded from the display.

When to use

Use to test whether the effect of a treatment, procedure or biomarker differs across subgroups (stage, gender, …) — the interaction-effect question. For subgroup effects with no intervention variable, use the prognostic mode (effect_var unset).

Caveats

Interaction effects are estimated from the same data as the overall model — sparse subgroups give unstable interaction estimates, and levels with fewer than 5 patients or 3 events are excluded from the display. The two-level requirement makes the effect variable a contrast, not a multi-category factor.

lifelines — the survival-analysis Python library this analysis fits its Cox models with. Documentation: https://lifelines.readthedocs.io/en/latest/ — paper: Davidson-Pilon, C. (2019). lifelines: survival analysis in Python. Journal of Open Source Software, 4(40), 1317. https://doi.org/10.21105/joss.01317.

Example questions

example questions
  • forest — interaction mode: effect of a clinical characteristic across subgroups

  • forest — interaction mode: effect of a treatment or procedure across subgroups

Input columns

input columns
column
type
required
description

patient_id

categorical, any

required

Unique patient identifier — one row per patient.

time

numeric

required

Survival duration in years (aliased from the raw column in SQL, e.g. overall_survival AS time or progression_free_survival AS time).

event

boolean, numeric

required

Event indicator (boolean or 0/1; True/1 = event occurred). Aliased in SQL, e.g. os_event AS event or pfs_event AS event.

<stratify_by columns>

categorical

required

One or more categorical columns used as subgroup variables (e.g. 'gender', 'stage'). Listed in the stratify_by parameter.

<adjust_vars columns>

numeric, categorical

optional

Zero or more columns to include as covariates in the Cox model (e.g. 'age'). Listed in the adjust_vars parameter. Their rows are hidden by default; set show_ad…

Visualizations

  • forest How to read: The plot displays one row per subgroup level, headed by an 'Overall' row showing the cohort-wide effect. Points represent hazard ratios for the effect variable within each stratum, whiskers show 95% confidence intervals, and the dashed vertical line marks no effect (HR = 1). A confidence interval crossing 1 indicates that the effect within that specific subgroup is not statistically significant. The x-axis is log-scaled by default. Hovering over a point displays the exact p-value; levels with fewer than 5 patients or 3 events are excluded.

Last updated

Was this helpful?