> For the complete documentation index, see [llms.txt](https://docs.owkin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.owkin.com/explore-and-analyse-data/data-analysis/survival-outcomes/cox-survival-models.md). Agents can also search and read this documentation through its [MCP server](https://docs.owkin.com/~gitbook/mcp).

# 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

<details>

<summary><code>example questions</code></summary>

* 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

</details>

### Input columns

<details>

<summary><code>input columns</code></summary>

| 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… |

</details>

### 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

<details>

<summary><code>analysis_name, analysis_params, viz_params</code></summary>

```json
{
  "analysis_name": "survival_analysis",
  "analysis_params": {
    "effect_var": null,
    "stratify_by": [
      "gender",
      "condition_stage"
    ],
    "adjust_vars": [],
    "multivariate": true,
    "outcome_label": "Overall Survival",
    "time_unit": "years"
  },
  "viz_params": {
    "plot_name": "forest",
    "title": "Overall Survival Subgroup Effects by Gender and Stage \u2014 Bladder Cancer (TCGA)"
  }
}
```

</details>

#### Visualization — `forest`

![Overall Survival Subgroup Effects by Gender and Stage — Bladder Cancer (TCGA)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-c5a5387e5444204d42fce5b1821c4b936b5d8ddd%2Fsurvival_analysis__prognostic__forest.png?alt=media)

#### Output table

<details>

<summary><code>statistical_tests</code> (6 rows)</summary>

| 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** |

</details>

### Example analysis 2

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

#### Analysis parameters

<details>

<summary><code>analysis_name, analysis_params, viz_params</code></summary>

```json
{
  "analysis_name": "survival_analysis",
  "analysis_params": {
    "plot_name": "kaplan_meier",
    "stratify_by": [
      "gender"
    ],
    "adjust_vars": [
      "age",
      "smoking_status"
    ],
    "time_unit": "years"
  },
  "viz_params": {
    "plot_name": "kaplan_meier",
    "outcome_label": "Overall Survival",
    "group_label": "Gender",
    "show_ci": true,
    "title": "Cox-Adjusted Overall Survival by Gender (Adjusted for Age and Smoking Status)"
  }
}
```

</details>

#### Visualization — `kaplan_meier`

![Cox-Adjusted Overall Survival by Gender (Adjusted for Age and Smoking Status)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-adb06b7fb6b2a5593d6a11dc66cde66251a057e1%2Fsurvival_analysis__prognostic__kaplan_meier.png?alt=media)

#### Output table

<details>

<summary><code>statistical_tests</code> (5 rows)</summary>

| 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    |

</details>

## 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

<details>

<summary><code>example questions</code></summary>

* forest — interaction mode: effect of a clinical characteristic across subgroups
* forest — interaction mode: effect of a treatment or procedure across subgroups

</details>

### Input columns

<details>

<summary><code>input columns</code></summary>

| 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… |

</details>

### 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.owkin.com/explore-and-analyse-data/data-analysis/survival-outcomes/cox-survival-models.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
