> 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/single-cell/cell-type-proportions.md).

# Cell-type proportions

Quantify and compare cell-type composition across samples or patient groups using individual cell or spot counts, or precomputed densities and fractions.

Quantify and compare cell-type composition across samples or patient groups using individual cell or spot counts, or precomputed densities and fractions.

## Count-based proportions (boxplot)

### Description

#### Analysis summary

Computes how a cohort's units — samples, patients or slides — are composed: within each denominator unit, the share of its entities (most often cells) falling in each category of a grouping variable, one proportion per unit.

#### Computation

Within every denominator unit, the entities falling in each category of the grouping variable (optionally split by a stratification variable) are counted and divided by the unit's total entity count, giving per-unit proportions that sum to 1. The output keeps one proportion per denominator unit rather than a single average composition, so the unit-to-unit (patient-to-patient, slide-to-slide) biological spread is preserved. Pairwise statistical comparisons of the proportions between groups (within each stratum when the data is stratified) are computed automatically and returned with the results.

#### When to use

Use for composition and abundance questions whenever the entities can be counted individually: cell-type proportions per sample in single-cell or spatial transcriptomics, spot composition per slide, and so on. It answers 'how much of each unit is X?' — not 'what fraction of cells express gene Y?': that is an expression question, answered by sparse\_aggregation\_analysis. When only pre-aggregated densities are available and entities cannot be counted, use the density mode of this analysis instead.

#### Caveats

A denominator unit with few entities (e.g. a sample with a handful of cells) yields noisy proportions, and proportions of rare categories are unstable across units.

### Example questions

<details>

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

* Single-cell cell type proportions per sample
* Single-cell cell type proportions per sample, stratified

</details>

### Input columns

<details>

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

| column       | type        | required | description                                                                                                                                                      |
| ------------ | ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| count\_index | any         | required | Entity to count per denominator (e.g. cell\_id); each distinct value is counted once per denominator, so each entity must appear on its own row.                 |
| denominator  | any         | required | Denominator unit — proportions sum to 1 per value here.                                                                                                          |
| x\_group     | categorical | required | Primary grouping variable (e.g. condition, cell type).                                                                                                           |
| y\_group     | categorical | optional | Stratification variable (e.g. gender, condition), or — in density mode — the category whose share is computed.                                                   |
| patient\_id  | categorical | required | Patient identifier. Always required, even in density mode where it isn't used by this analysis itself, because population summary statistics are computed from … |

</details>

### Visualizations

* `boxplot` How to read: Each box shows the distribution of per-denominator proportions for one group: the centre line is the median, the box spans the interquartile range of the values, and the dots are the individual denominator units (samples, patients or slides) — their vertical spread is the unit-to-unit variability of the composition. When the data is stratified, side-by-side boxes are keyed by the legend. Significance brackets with stars mark groups with at least one significant pairwise comparison after multiple-testing correction (★ p<0.05, ★★ p<0.01, ★★★ p<0.001, ★★★★ p<0.0001). The y-axis is the share of each denominator unit, in percent.

### Example analysis 1

#### Name — Cell Type Proportions (MOSAIC, Age >= 40)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "proportion_analysis",
  "analysis_params": {},
  "viz_params": {
    "count_index_label": "Cell",
    "denominator_label": "Sample",
    "x_group_label": "Cell Type",
    "plot_name": "boxplot",
    "title": "Cell Type Proportions (MOSAIC, Age >= 40)"
  }
}
```

</details>

#### Visualization — `boxplot`

![Cell Type Proportions (MOSAIC, Age >= 40)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-b20c567dc2a0047817e911de2f4997b0f0e7d5e3%2Fproportion_analysis__count__boxplot.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (first 10 of 15 rows)</summary>

| x\_group               | n  | mean      | std      | min       | p10       | p25       | p50       | p75       | p90       | max       |
| ---------------------- | -- | --------- | -------- | --------- | --------- | --------- | --------- | --------- | --------- | --------- |
| B\_cell                | 28 | 0.02075   | 0.03623  | 0.0003849 | 0.001079  | 0.00206   | 0.004988  | 0.02614   | 0.0378    | 0.1764    |
| DC                     | 28 | 0.01119   | 0.008652 | 0.0001374 | 0.001981  | 0.004234  | 0.01051   | 0.01488   | 0.01773   | 0.03785   |
| Endothelial            | 29 | 0.05131   | 0.02365  | 0.01214   | 0.02499   | 0.04483   | 0.04934   | 0.0568    | 0.06959   | 0.147     |
| Epithelial\_absorptive | 1  | 0.0001093 |          | 0.0001093 | 0.0001093 | 0.0001093 | 0.0001093 | 0.0001093 | 0.0001093 | 0.0001093 |
| Epithelial\_other      | 22 | 0.008505  | 0.01495  | 0.0001047 | 0.000138  | 0.0005463 | 0.00279   | 0.008379  | 0.02233   | 0.05648   |
| Epithelial\_secretory  | 7  | 0.02174   | 0.03162  | 0.0001489 | 0.0001965 | 0.0004309 | 0.001995  | 0.03338   | 0.03338   | 0.08501   |
| Fibroblast             | 29 | 0.1843    | 0.1163   | 0.01821   | 0.0364    | 0.1145    | 0.1729    | 0.2357    | 0.3209    | 0.5269    |
| Granulocyte            | 29 | 0.007664  | 0.01424  | 0.000298  | 0.0007236 | 0.001887  | 0.003267  | 0.005027  | 0.01868   | 0.06557   |
| Malignant              | 29 | 0.3266    | 0.1383   | 0.02004   | 0.2029    | 0.2223    | 0.3231    | 0.3924    | 0.5534    | 0.5966    |
| Mast                   | 28 | 0.005844  | 0.005115 | 0.0004717 | 0.0007444 | 0.00154   | 0.004471  | 0.008185  | 0.01292   | 0.01837   |

</details>

<details>

<summary><code>statistical_tests</code> (first 10 of 105 rows)</summary>

| Test used for pairwise comparison | Contrast                    | Statistic | Mean Difference | Higher Group | P-value   | Adjusted P-value | Significance level | comparison\_a | comparison\_b  |
| --------------------------------- | --------------------------- | --------- | --------------- | ------------ | --------- | ---------------- | ------------------ | ------------- | -------------- |
| wilcoxon                          | (Malignant, Granulocyte)    | 839.0     | 0.3189          | Malignant    | 8.008e-11 | 1.248e-09        | ★★★★               | Malignant     | Granulocyte    |
| wilcoxon                          | (MoMac, Granulocyte)        | 838.0     | 0.1301          | MoMac        | 8.88e-11  | 1.248e-09        | ★★★★               | MoMac         | Granulocyte    |
| wilcoxon                          | (Malignant, Mast)           | 812.0     | 0.3207          | Malignant    | 9.623e-11 | 1.248e-09        | ★★★★               | Malignant     | Mast           |
| wilcoxon                          | (Mast, MoMac)               | 0.0       | -0.1319         | MoMac        | 9.623e-11 | 1.248e-09        | ★★★★               | Mast          | MoMac          |
| wilcoxon                          | (MoMac, DC)                 | 812.0     | 0.1266          | MoMac        | 9.623e-11 | 1.248e-09        | ★★★★               | MoMac         | DC             |
| wilcoxon                          | (MoMac, Stromal other)      | 812.0     | 0.132           | MoMac        | 9.623e-11 | 1.248e-09        | ★★★★               | MoMac         | Stromal\_other |
| wilcoxon                          | (Malignant, Stromal other)  | 811.0     | 0.3208          | Malignant    | 1.069e-10 | 1.248e-09        | ★★★★               | Malignant     | Stromal\_other |
| wilcoxon                          | (Mast, Fibroblast)          | 1.0       | -0.1784         | Fibroblast   | 1.069e-10 | 1.248e-09        | ★★★★               | Mast          | Fibroblast     |
| wilcoxon                          | (Fibroblast, Stromal other) | 811.0     | 0.1785          | Fibroblast   | 1.069e-10 | 1.248e-09        | ★★★★               | Fibroblast    | Stromal\_other |
| wilcoxon                          | (Malignant, DC)             | 809.0     | 0.3154          | Malignant    | 1.32e-10  | 1.282e-09        | ★★★★               | Malignant     | DC             |

</details>

## Density-based proportions (stacked bar)

### Description

#### Analysis summary

Computes the mean composition of each group from pre-computed measurements that cannot be decomposed into countable entities — for example histomics-derived cell densities per slide or tissue region — as the mean share of each category in the group's composition.

#### Computation

Each measurement is first normalised to a proportion within its denominator unit (the unit's measurements sum to 1), and those per-unit proportions are then averaged within each group to give the mean composition — one mean share per category per group. Missing category-unit combinations are counted as zero before averaging, so a rare category's mean is taken over all units, not only those where it appears. Pairwise statistical comparisons between the categories within each group are computed automatically and returned with the results.

#### When to use

Use when the input provides pre-aggregated density or fraction values (e.g. histomics cell densities) rather than countable entities. When the entities can be counted individually, prefer the count mode of this analysis, which keeps the unit-to-unit variability visible instead of averaging it away.

#### Caveats

Averaging across denominator units yields the typical composition of each group but not the unit-to-unit spread.

### Example questions

<details>

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

* Histomics cell type density proportions across groups

</details>

### Input columns

<details>

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

| column      | type        | required | description                                                                                                                                                      |
| ----------- | ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| denominator | any         | required | Denominator unit — proportions sum to 1 per value here.                                                                                                          |
| value       | numeric     | required | Pre-computed numeric measurement (e.g. cell density) to normalise within each denominator.                                                                       |
| x\_group    | categorical | required | Primary grouping variable (e.g. condition, cell type).                                                                                                           |
| y\_group    | categorical | optional | Stratification variable (e.g. gender, condition), or — in density mode — the category whose share is computed.                                                   |
| patient\_id | categorical | required | Patient identifier. Always required, even in density mode where it isn't used by this analysis itself, because population summary statistics are computed from … |

</details>

### Visualizations

* `bar` How to read: Each bar is one group; its stacked segments (keyed by the legend) show the mean share of each category in the group's composition, summing to 100%, with the percentage written inside each segment. The chart shows the typical composition per group but not the unit-to-unit spread — use the count mode's boxplot for that. Pairwise comparisons between the categories within each group are reported in the accompanying statistical table.

### Example analysis 1

#### Name — Histomics Cell Type Proportions by Gender (TCGA Bladder Cancer, Age > 40)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "proportion_analysis",
  "analysis_params": {
    "proportion_type": "density"
  },
  "viz_params": {
    "x_group_label": "Gender",
    "y_group_label": "Cell Type",
    "value_label": "Proportion (%)",
    "plot_name": "bar",
    "title": "Histomics Cell Type Proportions by Gender (TCGA Bladder Cancer, Age > 40)"
  }
}
```

</details>

#### Visualization — `bar`

![Histomics Cell Type Proportions by Gender (TCGA Bladder Cancer, Age > 40)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-c2ef16a9480ed3d628fc9a04940cd7ac4f594c09%2Fproportion_analysis__density__bar.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (first 10 of 12 rows)</summary>

| x\_group | y\_group                         | n   | mean   | std    | min    | p10    | p25    | p50    | p75    | p90    | max    |
| -------- | -------------------------------- | --- | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ |
| female   | density\_cancer\_cell\_in\_tumor | 108 | 2295.0 | 1448.0 | 206.3  | 724.1  | 1365.0 | 2170.0 | 2760.0 | 3955.0 | 8442.0 |
| female   | density\_eosinophils\_in\_tumor  | 108 | 30.65  | 36.85  | 0.7768 | 3.069  | 9.041  | 18.43  | 36.58  | 61.76  | 226.9  |
| female   | density\_fibroblasts\_in\_tumor  | 108 | 456.9  | 252.2  | 109.2  | 199.5  | 296.0  | 425.4  | 547.3  | 710.5  | 1806.0 |
| female   | density\_lymphocytes\_in\_tumor  | 108 | 558.7  | 561.7  | 9.979  | 127.3  | 213.4  | 403.0  | 658.6  | 1271.0 | 3965.0 |
| female   | density\_neutrophils\_in\_tumor  | 108 | 45.35  | 63.75  | 1.17   | 6.979  | 11.71  | 24.23  | 52.14  | 94.89  | 371.5  |
| female   | density\_plasmocytes\_in\_tumor  | 108 | 43.39  | 83.18  | 0.4036 | 1.107  | 3.901  | 12.28  | 36.58  | 97.18  | 447.7  |
| male     | density\_cancer\_cell\_in\_tumor | 310 | 2740.0 | 1554.0 | 61.56  | 1163.0 | 1648.0 | 2414.0 | 3571.0 | 4880.0 | 9861.0 |
| male     | density\_eosinophils\_in\_tumor  | 310 | 26.66  | 42.48  | 0.1785 | 1.98   | 4.501  | 13.07  | 28.11  | 73.23  | 396.6  |
| male     | density\_fibroblasts\_in\_tumor  | 310 | 417.0  | 243.8  | 40.03  | 143.2  | 237.3  | 375.4  | 544.2  | 752.5  | 1435.0 |
| male     | density\_lymphocytes\_in\_tumor  | 310 | 454.3  | 475.1  | 9.718  | 62.71  | 145.7  | 315.0  | 564.5  | 1056.0 | 2860.0 |

</details>

<details>

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

| Test used for pairwise comparison | Group                        | Contrast       | Statistic | Mean Difference | Higher Group | P-value  | Adjusted P-value | Significance level | comparison\_a | comparison\_b |
| --------------------------------- | ---------------------------- | -------------- | --------- | --------------- | ------------ | -------- | ---------------- | ------------------ | ------------- | ------------- |
| wilcoxon                          | Density eosinophils in tumor | (Female, Male) | 19900.0   | 3.987           | Female       | 0.003517 | 0.01623          | ★                  | female        | male          |
| wilcoxon                          | Density cancer cell in tumor | (Female, Male) | 13730.0   | -445.1          | Male         | 0.005409 | 0.01623          | ★                  | female        | male          |
| wilcoxon                          | Density neutrophils in tumor | (Female, Male) | 19540.0   | 3.903           | Female       | 0.009516 | 0.01903          | ★                  | female        | male          |
| wilcoxon                          | Density lymphocytes in tumor | (Female, Male) | 19190.0   | 104.3           | Female       | 0.02337  | 0.03505          | ★                  | female        | male          |
| wilcoxon                          | Density fibroblasts in tumor | (Female, Male) | 18610.0   | 39.89           | Female       | 0.0833   | 0.09996          |                    | female        | male          |
| wilcoxon                          | Density plasmocytes in tumor | (Female, Male) | 17640.0   | 5.963           | Female       | 0.4044   | 0.4044           |                    | female        | male          |

</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/single-cell/cell-type-proportions.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.
