> 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-spatial/single-cell-spatial-feature-correlation.md).

# Single-cell / Spatial feature correlation

Compute pairwise Pearson/Spearman correlation and co-occurrence matrices between features, optionally stratified by a grouping variable.

Compute pairwise Pearson/Spearman correlation and co-occurrence matrices between features, optionally stratified by a grouping variable.

## Sparse correlation + co-occurrence dotplot

### Description

#### Analysis summary

Computes, between every pair of features over sparse observations (cells or spots), both a correlation coefficient of their expression levels and the share of observations co-expressing both — the two faces of pairwise association in sparse data.

#### Computation

Per stratum of the optional grouping variable (or globally when absent), the observations are pivoted to a wide observation-by-feature matrix; observations missing any feature value are excluded, zero-valued ones kept. Every feature pair then gets a Pearson or Spearman correlation coefficient over the expression values, its two-sided p-value, and the co-expression share — the fraction of observations where both features' presence signals are above zero — with the observation counts backing each. The diagonal (a feature against itself) carries a coefficient of 0. Gene signatures collapse their member genes into per-observation averages before the matrix is computed.

#### When to use

Use for sparse single-cell or spatial-transcriptomics data, where the binary expressed/not-expressed dimension is informative alongside the correlation: it answers 'which features correlate and which actually co-occur'. For correlation matrices on bulk (dense) data, use correlation\_analysis instead; for the overlap between exactly two features, use coexpression\_analysis.

#### Caveats

Correlation over sparse counts is dominated by the many zero-zero pairs — a high correlation can mean shared abundance rather than shared regulation, which is what the co-expression share disambiguates. Each p-value is uncorrected for the many pairs tested. Observations missing any feature of the panel are dropped, so the effective cohort is the intersection across the panel.

### Example questions

<details>

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

* Single-cell pairwise gene correlation per cell type
* Single-cell pairwise gene signature correlation per cell type

</details>

### Input columns

<details>

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

| column          | type        | required | description                                                                                                                                                       |
| --------------- | ----------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| index           | any         | required | Unique observation identifier used to align feature vectors across rows. e.g. cell barcode (scRNA-seq), spot barcode (Visium), sample\_id (bulk).                 |
| value\_sparsity | numeric     | required | Raw presence/absence signal — value\_sparsity > 0 marks an observation as expressing/present. Used exclusively to compute co-occurrence percentage, not for corr… |
| value           | numeric     | required | Continuous quantity to correlate across observations. e.g. count\_lognorm or count\_scaled (scRNA-seq / Visium), normalised bulk expression, z-score.             |
| x\_group        | categorical | required | Feature label — each unique value becomes both a row and a column in the correlation matrix. e.g. gene\_name, pathway\_score\_name, protein\_name.                |
| y\_group        | categorical | optional | Stratification variable. When provided, one correlation matrix is computed per unique value. e.g. cell\_type, spot\_cluster, tissue\_region, sample\_group.       |
| patient\_id     | categorical | required | Patient identifier required for population summary statistics.                                                                                                    |

</details>

### Visualizations

* `dotplot` How to read: One dot per feature pair: its colour encodes the correlation coefficient on a diverging red-blue scale centred on zero (red positive, blue negative) and its area the share of observations co-expressing both (size legend). The two axes are the same feature list — the matrix is symmetric — and the diagonal carries no information. When the data is stratified, a dropdown switches between strata. Hovering a dot shows the coefficient, the p-value and the co-expression counts; the accompanying statistical table repeats the coefficients and p-values, each unordered pair once.

### Example analysis 1

#### Name — Gene Correlation Heatmap for ERBB2, TP53, and ROR1 in Immune Cells (Age > 40)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "sparse_correlation_analysis",
  "analysis_params": {
    "correlation_method": "pearson"
  },
  "viz_params": {
    "x_group_label": "Gene",
    "y_group_label": "Cell Type (Mid Level)",
    "correlation_label": "Pearson Correlation",
    "co_expression_label": "Co-expression",
    "plot_name": "dotplot",
    "title": "Gene Correlation Heatmap for ERBB2, TP53, and ROR1 in Immune Cells (Age > 40)"
  }
}
```

</details>

#### Visualization — `dotplot`

![Gene Correlation Heatmap for ERBB2, TP53, and ROR1 in Immune Cells (Age > 40)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-d4e2f580de999698ce188dfcddcf4160fdd61c41%2Fsparse_correlation_analysis__sparse_correlation__dotplot.png?alt=media)

#### Output table

<details>

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

| y\_group    | x\_group\_a | x\_group\_b | pearson\_correlation | p\_value  | co\_expression | n    | n\_non\_zeros\_a | n\_non\_zeros\_b | n\_co\_expressed |
| ----------- | ----------- | ----------- | -------------------- | --------- | -------------- | ---- | ---------------- | ---------------- | ---------------- |
| Mast        | ERBB2       | ROR1        | 0.2012               | 8.411e-08 | 0.001435       | 697  | 15               | 2                | 1                |
| Plasma      | ERBB2       | TP53        | 0.05437              | 0.0006178 | 0.004291       | 3962 | 130              | 223              | 17               |
| Granulocyte | ROR1        | TP53        | 0.1444               | 0.002621  | 0.002315       | 432  | 2                | 15               | 1                |
| Granulocyte | ERBB2       | TP53        | 0.07783              | 0.1062    | 0.006944       | 432  | 26               | 15               | 3                |
| MoMac       | ERBB2       | ROR1        | 0.01668              | 0.1321    | 0.0003681      | 8150 | 239              | 46               | 3                |
| Plasma      | ROR1        | TP53        | 0.02199              | 0.1663    | 0.0007572      | 3962 | 20               | 223              | 3                |
| B\_cell     | ERBB2       | ROR1        | 0.02714              | 0.2785    | 0.0006266      | 1596 | 44               | 16               | 1                |
| DC          | ERBB2       | TP53        | 0.02978              | 0.2926    | 0.01119        | 1251 | 61               | 187              | 14               |
| B\_cell     | ERBB2       | TP53        | 0.01836              | 0.4635    | 0.004386       | 1596 | 44               | 170              | 7                |
| T\_NK       | ERBB2       | ROR1        | -0.007992            | 0.4723    | 0.0            | 8091 | 182              | 23               | 0                |

</details>

<details>

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

| y\_group    | x\_group\_a | x\_group\_b | pearson\_correlation | p\_value  | co\_expression | n    | n\_non\_zeros\_a | n\_non\_zeros\_b | n\_co\_expressed |
| ----------- | ----------- | ----------- | -------------------- | --------- | -------------- | ---- | ---------------- | ---------------- | ---------------- |
| Mast        | ERBB2       | ROR1        | 0.2012               | 8.411e-08 | 0.001435       | 697  | 15               | 2                | 1                |
| Plasma      | ERBB2       | TP53        | 0.05437              | 0.0006178 | 0.004291       | 3962 | 130              | 223              | 17               |
| Granulocyte | ROR1        | TP53        | 0.1444               | 0.002621  | 0.002315       | 432  | 2                | 15               | 1                |
| Granulocyte | ERBB2       | TP53        | 0.07783              | 0.1062    | 0.006944       | 432  | 26               | 15               | 3                |
| MoMac       | ERBB2       | ROR1        | 0.01668              | 0.1321    | 0.0003681      | 8150 | 239              | 46               | 3                |
| Plasma      | ROR1        | TP53        | 0.02199              | 0.1663    | 0.0007572      | 3962 | 20               | 223              | 3                |
| B\_cell     | ERBB2       | ROR1        | 0.02714              | 0.2785    | 0.0006266      | 1596 | 44               | 16               | 1                |
| DC          | ERBB2       | TP53        | 0.02978              | 0.2926    | 0.01119        | 1251 | 61               | 187              | 14               |
| B\_cell     | ERBB2       | TP53        | 0.01836              | 0.4635    | 0.004386       | 1596 | 44               | 170              | 7                |
| T\_NK       | ERBB2       | ROR1        | -0.007992            | 0.4723    | 0.0            | 8091 | 182              | 23               | 0                |

</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-spatial/single-cell-spatial-feature-correlation.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.
