Skip to content

Keep the y axis of the outliers panel on the residuals - #487

Closed
jmgirard wants to merge 13 commits into
easystats:mainfrom
jmgirard:outliers-panel-y-axis
Closed

jmgirard wants to merge 13 commits into
easystats:mainfrom
jmgirard:outliers-panel-y-axis

Conversation

@jmgirard

@jmgirard jmgirard commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

In the outliers panel of check_model() and plot() for check_outliers(), the Cook's distance contour lines set the y axis, so it grew with the number of observations (easystats/performance#894, #464). For an lm() with 400 observations and residuals from -2.7 to 3.6, the axis went from about -21 to 21. The axis now follows the residuals, and the contour lines are cut at their range. If no line is left in the panel, the subtitle says that all points are inside the contour lines.

The snapshots that show this panel are not re-recorded here, because they already fail on main on my machine (local package versions). They need a re-record in CI:

  • check-model-outliers, check-model-panel, check-outliers-default, check-outliers-modern, outliers-plot-low-n, and the default plot.see_check_outliers snapshot: shorter y axis, cut contour lines.

Refs easystats/performance#894

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Snapshots need re-recording, and smoother scaling and all-NA subtitle cases remain unresolved.

1 open issue
What changed in this PR

This PR keeps the outliers panel y-axis bounded by standardized residuals instead of Cook’s distance contours.

Changes:

  • Clips contours and adjusts labels/subtitles.
  • Preserves residual scaling when dots are hidden.
  • Adds regression tests and updates NEWS/version metadata.
File Summary
R/​plot.check_outliers.dots.R Implements contour clipping and residual-based scaling.
tests/​testthat/​test-check_outliers_y_axis.R Tests axes, contours, labels, subtitles, and sampling.
tests/​testthat/​test-check_model_show_smooth.R Updates contour expectations.
NEWS.md Documents the behavior change.
DESCRIPTION Bumps the package version.

Review effort: Lite

Comment thread R/plot.check_outliers.dots.R Resolved
Cut the Cook's distance contour lines where they leave the range of the
standardized residuals, so that the lines no longer stretch the y axis as
the number of observations grows (easystats/performance#894). Labels of cut
lines move to the inner side of the line, or to the largest leverage when the
line does not reach 80% of the leverage range. The subtitle says when no line
is inside the residual range.
Without dots, a blank layer keeps the y axis on the residual range, so the
contour lines are still cut there and drawn. The subtitle says that all
points are inside only if the contour lines could be computed, and a cut
line of a single point is dropped. The new tests skip on CRAN and without
ggrepel.
…points are inside, and reword two test comments
…oints are inside

Rows left out by the sampling above maximum_dots can lie between contour
levels, so the subtitle now also needs every Cook's distance below the
smallest level. The show_smooth test checks that the remaining contour line
is the upper one and skips on CRAN. The ggrepel skip now covers only the
tests of the y range with point labels.
@jmgirard
jmgirard force-pushed the outliers-panel-y-axis branch from 3104192 to 4544d45 Compare October 20, 2026 20:29
@jmgirard

Copy link
Copy Markdown
Contributor Author

#487 (review)

  • R/plot.check_outliers.dots.R:167 (snapshots): not changed. These snapshots already fail on main on my machine because of local package versions, so they need a re-record in the CI environment.
  • Smoother scaling: left for a follow-up.
  • All-NA subtitle cases: not changed. All-NA contour levels are tested and keep the old subtitle.

@strengejacke

Copy link
Copy Markdown
Member

I have uploaded some updated snapshots for comparison.
However, this PR removes all contour lines from the outliers plot, which should not be the case.
Furthermore, following test fails in tests\testthat\test-check_outliers_y_axis.R:

Error in b$data[[.annotations(p, "GeomText")]]: attempt to select less than one element in get1index

test_that("outliers panel draws only contour lines that reach the residuals", {
  m <- lm(y ~ x, data = rbind(d, data.frame(x = 0, y = 6.8)))
  p <- plot(.outliers_check(m))
  expect_length(.annotations(p, "GeomLine"), 1)
  b <- ggplot2::ggplot_build(p)
  label <- b$data[[.annotations(p, "GeomText")]]
  expect_identical(nrow(label), 1L)
  expect_identical(label$x, max(b$data[[1]]$x))
})

@strengejacke strengejacke left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In summary: Contour lines should not be removed from plots

@jmgirard

jmgirard commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, we should close this PR without merging. I thought this would help easystats/performance#894, but the LOESS changes fixed that and this isn't necessary.

@jmgirard jmgirard closed this Nov 2, 2026
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.

3 participants