Skip to content

Add residual plotting#14

Merged
choutkaj merged 5 commits intomainfrom
refactor/residual-plotting
Apr 28, 2026
Merged

Add residual plotting#14
choutkaj merged 5 commits intomainfrom
refactor/residual-plotting

Conversation

@choutkaj
Copy link
Copy Markdown
Owner

Summary

This PR adds residual plotting to the Axes-first plotting API.

Included:

  • Adds standalone plot_residuals()
  • Computes residuals as observed - predicted
  • Supports aggregated residuals, matching the default technical-replicate aggregation used in plotting observations
  • Supports raw replicate residuals with aggregate=False
  • Supports compound and experiment filtering
  • Adds optional zero reference line, enabled by default
  • Supports log or linear x-axis scaling
  • Labels residual units using DoseResponseData.response_unit
  • Exports plot_residuals() from bindcurve.plotting and top-level bindcurve
  • Adds tests for:
    • aggregated residual plotting
    • raw replicate residual plotting
    • disabling the zero line
    • linear x-axis scaling
    • missing successful fits

Notes

This PR keeps residual plotting as a standalone helper so users can compose diagnostics flexibly:

fig, ax = plt.subplots()
bc.plot_residuals(data, results, ax=ax)

It does not add a multi-panel residual layout yet. That can come later as a compound/grid plotting layer.

Test plan

  • Existing pytest workflow should run the expanded plotting tests
  • Existing Ruff workflow should lint the plotting package and tests
  • Branch is cleanly ahead of main with behind_by=0

@choutkaj choutkaj merged commit 15e02f0 into main Apr 28, 2026
3 of 4 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dbbf3d5987

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +321 to +322
if fit.experiment_id is not None:
fit_table = table[table["experiment_id"].astype(str) == str(fit.experiment_id)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle compound-summary fits when filtering residual rows

plot_residuals() drops all points for fits produced with FitSettings(strategy="per_compound_summary") because those fits have experiment_id="compound_summary", but raw observation tables only contain real experiment IDs (e.g., exp1, exp2). This filter makes fit_table empty, so the loop silently skips plotting residuals and users get an empty diagnostic despite having a successful fit. Please special-case summary fits (or any fit ID not present in the table) so residuals are computed from the aggregated compound-level observations instead of filtering everything out.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant