> 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/longitudinal-clinical-data/longitudinal-trajectories.md). Agents can also search and read this documentation through its [MCP server](https://docs.owkin.com/~gitbook/mcp).

# Longitudinal trajectories

Explore how repeated numerical measurements, such as PSA, tumor mutational burden, or tumor size, change over time within patients and across patient groups.

Explore how repeated numerical measurements, such as PSA, tumor mutational burden, or tumor size, change over time within patients and across patient groups.

## Individual patient trajectories

### Description

#### Analysis summary

Preserves each patient's repeated numeric measurements over time without combining patients or assigning categories. Supports inspection of individual longitudinal changes.

#### Computation

Retains unique patient/time/measurement combinations sorted by patient and time. An optional baseline shift subtracts each patient's earliest time, converting dates to elapsed days; alternatively, ordinal alignment replaces successive observations with shared visit-rank labels. The result table contains individual measurements and original or transformed times. A single descriptive row summarises all retained patients: distinct-patient count, observation count, mean, median, minimum, maximum and sample standard deviation of the measurements across time. No longitudinal model, change estimate or hypothesis test is fitted.

#### When to use

Use for 'how does this measurement change in each patient?' with repeated samples or events at different timepoints. This analysis is value-based: it requires a numeric measurement and summarises its evolution, not the occurrence, ordering or duration of clinical events. For which treatments a patient received, when, and for how long, use timeline\_analysis. Prefer the category-preserving mode to relate individual histories to patient categories, or the aggregated mode for cohort-level trends.

#### Caveats

Repeated observations at different times are needed to assess change. Exact duplicates are removed, but distinct values at the same patient/time remain separate. Null numeric measurements are excluded. Overall statistics pool observations across visits, so patients with more measurements contribute more heavily; these statistics are not within-patient change summaries. Ordinal alignment discards elapsed intervals and does not establish clinically equivalent visits; tied times receive separate ranks. Baseline shifting and ordinal alignment are mutually exclusive, and baseline shifting needs subtractable times.

### Example questions

<details>

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

* Show me the PSA over time for each patient.
* Plot per-patient SNV count trajectories.

</details>

### Input columns

<details>

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

| column      | type                       | required | description                                                                             |
| ----------- | -------------------------- | -------- | --------------------------------------------------------------------------------------- |
| index       | any                        | required | Event identifier. Smallest level of granularity.                                        |
| time        | date, numeric, categorical | required | Observation time — alias any numeric, date, or categorical timepoint column AS time.    |
| value       | numeric                    | required | Measured numeric quantity (e.g. PSA, tumour size). Alias AS value.                      |
| patient\_id | any                        | required | Patient identifier. Required for per-patient trajectories and for population summaries. |

</details>

### Visualizations

* `lineplot` How to read: Each line connects one patient's observed measurements, with markers at recorded timepoints and a patient key in the legend. The vertical axis is the measured quantity; the horizontal axis is original time, elapsed time from the patient's first observation (days for date inputs), or ordinal visit labels after alignment. Colours distinguish patients. Rising or falling segments describe observed changes, not fitted trends or values measured between visits. Ordinal spacing does not encode elapsed duration. Only the first patients in sorted identifier order are drawn up to the configured limit; the returned table and descriptive summary still include all retained patients.

### Example analysis 1

#### Name — TMB Trajectories per Patient (MOSAIC Bladder)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "trajectory_analysis",
  "analysis_params": {
    "mode": "per_patient",
    "nb_groups": 10
  },
  "viz_params": {
    "plot_name": "lineplot",
    "title": "TMB Trajectories per Patient (MOSAIC Bladder)",
    "y_label": "TMB (mutations/Mb)",
    "group_label": "Patient ID",
    "x_label": "Date"
  }
}
```

</details>

#### Visualization — `lineplot`

![TMB Trajectories per Patient (MOSAIC Bladder)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-3817a13d4b0fb933c4e9d8ebd6656a75fc6566d5%2Ftrajectory_analysis__per_patient__lineplot.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (1 rows)</summary>

| n\_patients | n\_observations | mean  | median | min   | max   | std   |
| ----------- | --------------- | ----- | ------ | ----- | ----- | ----- |
| 15          | 15              | 43.15 | 37.56  | 27.73 | 99.89 | 18.96 |

</details>

## Individual patient trajectories with categories

### Description

#### Analysis summary

Preserves individual patients' repeated numeric measurements together with a patient category such as treatment arm or mutation status. Category membership does not combine patients' trajectories.

#### Computation

Retains unique patient/category/time/measurement combinations, sorted by patient and time, with either original times, per-patient elapsed times from baseline, or ordinal visit ranks. The result table keeps patient-level observations and their categories. The descriptive table contains one row per category with distinct-patient and observation counts, mean, median, minimum, maximum and sample standard deviation of measurements pooled across time. No between-category tests or longitudinal models are computed.

#### When to use

Use to inspect individual longitudinal changes while relating patients to a category, without averaging their histories. This analysis is value-based: it requires a numeric measurement and summarises its evolution, not the occurrence, ordering or duration of clinical events. For which treatments a patient received, when, and for how long, use timeline\_analysis. Prefer the per-patient mode when no category is needed, or the aggregated mode for a cohort-level summary at each timepoint.

#### Caveats

The category should be constant per patient; changing categories are not modelled as time-varying exposures. Records with null categories or numeric measurements are excluded. Category summaries pool observations over time rather than comparing changes, and uneven sampling weights frequently measured patients more heavily. Distinct measurements at tied times remain separate. Ordinal alignment discards duration and assigns separate ranks to tied times; matching ranks need not represent equivalent clinical visits. Baseline shifting and ordinal alignment are mutually exclusive.

### Example questions

<details>

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

* Show per-patient PSA trajectories coloured by gender.
* Plot tumour size per patient, coloured by mutation status, relative to baseline.

</details>

### Input columns

<details>

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

| column       | type                       | required | description                                                                                                                                                      |
| ------------ | -------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| index        | any                        | required | Event identifier. Smallest level of granularity.                                                                                                                 |
| time         | date, numeric, categorical | required | Observation time — alias any numeric, date, or categorical timepoint column AS time.                                                                             |
| value        | numeric                    | required | Measured numeric quantity (e.g. PSA, tumour size). Alias AS value.                                                                                               |
| patient\_id  | any                        | required | Patient identifier. Required for per-patient trajectories and for population summaries.                                                                          |
| color\_group | categorical, any           | required | Patient-level category retained with individual trajectories and used for descriptive summaries. No aggregation of trajectories is performed. Cannot be combine… |

</details>

### Visualizations

* `lineplot` How to read: Each line connects one patient's measurements and markers identify observed timepoints. Line colours and the legend identify categories, not category averages; multiple lines of the same colour remain separate patients. A patient's first retained category determines its line colour. The vertical axis is the measurement and the horizontal axis is original time, time from individual baseline, or ordinal visit rank. Compare within-category variability as well as differences between categories; connected segments are not fitted trends. The display limit selects patients in sorted identifier order, while returned observations and category statistics include all retained patients.

### Example analysis 1

#### Name — TMB Trajectories per Patient Colored by Gender (MOSAIC Bladder)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "trajectory_analysis",
  "analysis_params": {
    "mode": "colored",
    "nb_groups": 10
  },
  "viz_params": {
    "plot_name": "lineplot",
    "title": "TMB Trajectories per Patient Colored by Gender (MOSAIC Bladder)",
    "y_label": "TMB (mutations/Mb)",
    "group_label": "Gender",
    "x_label": "Date"
  }
}
```

</details>

#### Visualization — `lineplot`

![TMB Trajectories per Patient Colored by Gender (MOSAIC Bladder)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-3bac3766a71f50d43c2a5e0b425251880df04592%2Ftrajectory_analysis__colored__lineplot.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (2 rows)</summary>

| color\_group | n\_patients | n\_observations | mean  | median | min   | max   | std   |
| ------------ | ----------- | --------------- | ----- | ------ | ----- | ----- | ----- |
| female       | 4           | 4               | 56.1  | 47.02  | 30.46 | 99.89 | 30.47 |
| male         | 11          | 11              | 38.44 | 37.44  | 27.73 | 64.01 | 11.54 |

</details>

## Group-level longitudinal summaries

### Description

#### Analysis summary

Summarises repeated numeric measurements within patient groups to compare cohort-level patterns over time. Shared observation times or aligned visit ranks allow patients with different recording dates to contribute to comparable timepoints.

#### Computation

Deduplicates patient/group/time/measurement combinations and optionally shifts each patient's time to baseline or replaces it with ordinal visit ranks. Groups are retained in sorted order up to the requested limit. The returned table keeps patient observations rather than pre-aggregated timepoint values. The descriptive table contains one row per retained group with patient and observation counts, mean, median, minimum, maximum and sample standard deviation pooled across time. Timepoint summaries can use the requested mean or median of observations at exact shared times, or patient-weighted mean and median within time bins: repeated samples within a bin first yield one mean per patient. No repeated-measures model, group-difference test or change estimate is computed.

#### When to use

Use for 'how does the typical measurement evolve in each treatment arm or cohort?' when comparable timepoints are available. This analysis is value-based: it requires a numeric measurement and summarises its evolution, not the occurrence, ordering or duration of clinical events. For which treatments a patient received, when, and for how long, use timeline\_analysis. Prefer ordinal alignment when a common visit sequence is needed rather than actual elapsed intervals. Prefer either individual trajectory mode when patient-to-patient histories or heterogeneous responses matter.

#### Caveats

Aligned ranks do not guarantee clinically comparable visits and discard elapsed time. Changing patient composition over follow-up can mimic within-patient change. Returned group statistics pool observations, not timepoint summaries, and therefore weight frequent sampling more heavily. Exact-time observation summaries and binned patient-weighted summaries need not agree. The group limit also restricts returned data and statistics. Null groups or numeric measurements are excluded; tied times with different measurements remain separate and get separate ordinal ranks. Baseline shifting and ordinal alignment are mutually exclusive.

### Example questions

<details>

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

* Show the mean TMB over aligned timepoints per treatment arm.
* Plot the median tumour-size trajectory per cohort.

</details>

### Input columns

<details>

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

| column      | type                       | required | description                                                                                                                                                        |
| ----------- | -------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| index       | any                        | required | Event identifier. Smallest level of granularity.                                                                                                                   |
| time        | date, numeric, categorical | required | Observation time — alias any numeric, date, or categorical timepoint column AS time.                                                                               |
| value       | numeric                    | required | Measured numeric quantity (e.g. PSA, tumour size). Alias AS value.                                                                                                 |
| patient\_id | any                        | required | Patient identifier. Required for per-patient trajectories and for population summaries.                                                                            |
| x\_group    | categorical, any           | required | Grouping column for aggregated trajectories. Values are aggregated per (x\_group, time) pair (e.g. gender AS x\_group → one summary per gender and timepoint, usi… |

</details>

### Visualizations

* `lineplot` How to read: The vertical axis is the measurement and the horizontal axis is original time, elapsed time from each patient's baseline, or ordinal visits. In Plotly, one line per group connects the selected mean or median of observations at each exact shared time; colours and the legend identify groups. In ECharts, groups occupy separate panels: the solid line is the patient-weighted median and the dashed line the patient-weighted mean, regardless of the requested aggregation. Date inputs use calendar-month bins, numeric inputs use one-unit bins, and categorical visits remain distinct. Repeated samples in a bin first yield one mean per patient. For groups with at least 40 patients, shaded quantile fans span the 5th–95th percentiles in 5-point increments; these show patient variability, not confidence intervals. Hover text reports the bin's median, mean and patient count, plus outer percentiles when shown. Changes can reflect which patients were sampled, not just changes within patients.

### Example analysis 1

#### Name — Mean Measurement Trajectories by Metric (MOSAIC Bladder)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "trajectory_analysis",
  "analysis_params": {
    "mode": "aggregated"
  },
  "viz_params": {
    "plot_name": "lineplot",
    "title": "Mean Measurement Trajectories by Metric (MOSAIC Bladder)",
    "y_label": "Mean Value",
    "group_label": "Metric",
    "x_label": "Date"
  }
}
```

</details>

#### Visualization — `lineplot`

![Mean Measurement Trajectories by Metric (MOSAIC Bladder)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-ba3f3c11eb5ef776baca83ca88ff427445a101de%2Ftrajectory_analysis__aggregated__lineplot.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (8 rows)</summary>

| x\_group                           | n\_patients | n\_observations | mean    | median  | min      | max    | std     |
| ---------------------------------- | ----------- | --------------- | ------- | ------- | -------- | ------ | ------- |
| tmb                                | 15          | 15              | 43.15   | 37.56   | 27.73    | 99.89  | 18.96   |
| n\_snv\_target\_regions\_per\_mb   | 15          | 15              | 37.36   | 31.39   | 25.99    | 97.28  | 17.94   |
| genome\_instability\_index         | 15          | 15              | 0.02342 | 0.02252 | 0.003415 | 0.059  | 0.01607 |
| n\_indel\_target\_regions          | 15          | 15              | 193.1   | 99.0    | 45.0     | 788.0  | 221.4   |
| n\_indel                           | 15          | 15              | 358.7   | 230.0   | 164.0    | 1085.0 | 288.2   |
| n\_snv\_target\_regions            | 15          | 15              | 1246.0  | 1047.0  | 867.0    | 3245.0 | 598.4   |
| n\_indel\_target\_regions\_per\_mb | 15          | 15              | 5.79    | 2.968   | 1.349    | 23.62  | 6.638   |
| n\_snv                             | 15          | 15              | 2042.0  | 1846.0  | 1466.0   | 4736.0 | 816.2   |

</details>


---

# 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/longitudinal-clinical-data/longitudinal-trajectories.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.
