Skip to content

Fix ggplot2 ‘Groups with fewer than two datapoints’ warning in mcmc_nuts_treedepth()#412

Merged
jgabry merged 2 commits into
stan-dev:masterfrom
BjarkeHautop:fix-ggplot2-treedepth
Jan 5, 2026
Merged

Fix ggplot2 ‘Groups with fewer than two datapoints’ warning in mcmc_nuts_treedepth()#412
jgabry merged 2 commits into
stan-dev:masterfrom
BjarkeHautop:fix-ggplot2-treedepth

Conversation

@BjarkeHautop

@BjarkeHautop BjarkeHautop commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Currently, the following gives a warning (taken from test-mcmc-nuts.R)

> if (requireNamespace("rstanarm", quietly = TRUE)) {
+     ITER <- 1000
+     CHAINS <- 3
+     fit <- rstanarm::stan_glm(mpg ~ wt + am, data = mtcars,
+                               iter = ITER, chains = CHAINS,
+                               refresh = 0)
+     np <- nuts_params(fit)
+     lp <- log_posterior(fit)
+ }
> 
> mcmc_nuts_treedepth(np, lp, chain = CHAINS)
Warning messages:
1: Groups with fewer than two datapoints have been dropped.
ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes. 
2: Groups with fewer than two datapoints have been dropped.
ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.

This PR fixes the issue by filtering that there are at least 2 observations before calling geom_violin, so the dropping doesn't happen implicitly with a warning.

@BjarkeHautop BjarkeHautop marked this pull request as draft January 4, 2026 19:08
@BjarkeHautop BjarkeHautop marked this pull request as ready for review January 4, 2026 19:23
@jgabry

jgabry commented Jan 5, 2026

Copy link
Copy Markdown
Member

Great, thank you very much! Tests are running now.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (5a5b1e5) to head (cfb5055).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #412   +/-   ##
=======================================
  Coverage   98.61%   98.62%           
=======================================
  Files          35       35           
  Lines        5792     5798    +6     
=======================================
+ Hits         5712     5718    +6     
  Misses         80       80           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jgabry jgabry 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.

Changes look good and all tests are passing. Merging now. Thanks again!

@jgabry jgabry merged commit e6b90f6 into stan-dev:master Jan 5, 2026
6 checks passed
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