Skip to content

feature selection method using pearson residuals discrepancies #3452

Open

Description

@jflucier

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

Hi,

I have performed multiple way to do features selection using pearson residuals and methods return different results.

Method 1 plot:
Image

Method 2 plot:
Image

I dont understand why these 2 methods dont produce the same result.

Based on those graph I think the best is method 2 but would like to understand why these dont produce similar plots.

Thanks in advance for your help

Minimal code sample

### 1st method:
analytic_pearson = sc.experimental.pp.normalize_pearson_residuals(adata, inplace=False)
adata.layers["analytic_pearson_residuals"] = csr_matrix(analytic_pearson["X"])
sc.pp.highly_variable_genes(adata, layer="analytic_pearson_residuals", n_top_genes=4000)
ax = sns.scatterplot(
data=adata.var, x="means", y="dispersions", hue="highly_variable", s=5
)

## 2nd method:

fig, ax = plt.subplots(1, 1, figsize=(10, 5))
sc.experimental.pp.highly_variable_genes(
adata, flavor="pearson_residuals", n_top_genes=4000
)
ax = sns.scatterplot(
data=adata.var, x="means", y="dispersions", hue="highly_variable", s=5
)
ax.set_xscale("log")
ax.set_yscale("log")
ax.set_title("Feature selection using Pearson residuals normalisation (from highly_variable_genes flavor pearson_residuals)")
pdf.savefig(bbox_inches="tight")

Error output

Versions

Details

Activity

  1. added
    Triage 🩺
    on Jan 24, 2025
  2. jflucier commented on Jan 24, 2025

    @jflucier
    Author

    Another observation.

    If I run scry on same data, I get this plot:
    Image

    The same plot but using highly_variable_genes suing flavor pearson_residuals:
    Image

    Though the pearson_resdual flavor was a reimplementation of scry but maybe I got this wrong.

    Thanks for your help understanding this

  3. flying-sheep commented on Mar 11, 2025

    @flying-sheep
    Member

    Hi, good question! I’m not super up-to-date with this corner of scanpy.

    There’s a PR by @ktpolanski that implements the deviance method from scry: #1765

    I’ll investigate the state of the experimental functions and that PR and see how we can best move forward.

    I think @jlause implemented the scry method in #1715, but as said, I haven’t looked into it at all yet.

  4. added and removed
    Triage 🩺
    on Mar 11, 2025
  5. added this to the 1.12.0 milestone on Mar 11, 2025
  6. flying-sheep commented on Mar 11, 2025

    @flying-sheep
    Member

    also relevant: #2176

  7. modified the milestones: 1.12.0, 1.13.0 on Nov 10, 2025
  8. modified the milestones: 1.13.0, 1.14.0 on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions