feat(viz): per-facet shading for faceted regression-fit plots#9
Merged
Conversation
shade_p_value / shade_confidence_interval now accept per-term values so each
facet of a visualize_fit() plot is shaded from its own observed statistic /
interval, in both engines:
- per-term obs_stat: an observed FitResult, a term-keyed frame (term + estimate
or stat), or a dict -> {term: value}
- per-term endpoints: a term-keyed CI table (term, lower_ci, upper_ci)
- ShadeSpec carries an optional per_term mapping; InferPlot remembers the facet
terms (from visualize_fit) and dispatches to per-facet shading
- plotly shades each subplot via add_vline/add_vrect with row/col (infinite
tails clipped to that subplot's data range); plotnine adds term-keyed
geom_rect/geom_vline layers (inherit_aes=False) that land in the right panel
- FitResult.visualize() and visualize_fit() gain shade_pvalue=/shade_ci= kwargs
Scalar shading on single-panel plots is unchanged. Adding a per-term spec to a
non-faceted plot raises a clear error. Fixes the two Chapter 10 faceted
multiple-regression inference figures that previously rendered without shading.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two faceted multiple-regression inference plots in Chapter 10 showed the correct bootstrap/null distributions but without the shading overlay —
shade_p_value/shade_confidence_intervalwere scalar-only and couldn't shade per facet. This adds array/per-term shading so those figures shade like the R book, in both the plotly (default) and plotnine engines.What
shade_p_valueandshade_confidence_intervalnow accept per-term inputs:FitResult(term + estimate), aterm-keyed frame (term+estimate/stat), or adictterm,lower_ci,upper_ci)Each facet of a
visualize_fit()plot is then shaded from its own observed statistic / interval.ShadeSpeccarries an optionalper_termmapping;InferPlotremembers the facettermsfromvisualize_fit()and dispatches to per-facet shading.add_vline/add_vrectwithrow/col(infinite tails clipped to that subplot's data range).geom_rect/geom_vlinelayers (inherit_aes=False) land in the correct panel.FitResult.visualize()andvisualize_fit()gainshade_pvalue=/shade_ci=keyword args;+composition also works.Usage:
Notes
TypeError.🤖 Generated with Claude Code