Skip to content

Conversation

behramulukir
Copy link
Collaborator

@behramulukir behramulukir commented Sep 6, 2025

Until now, users were able to control the look of their divergent points via the np_style argument and scatter_style_np function. Even though the mcmc_scatter function provided some control over the look of main points, such as alpha and size of them, users were not able to change the shape of the main points.

This PR adds shape argument to mcmc_scatter to give users control over the shape of their main points, as requested by @avehtari in #45.

Tasks:

  • implement the argument
  • implement tests
  • update the documentation

Examples

x <- example_mcmc_draws(params = 6)
color_scheme_set("brightblue")

mcmc_scatter(x, pars = c("alpha", "sigma"), transform = list(sigma = "log"))
mcmc_scatter(x, pars = c("alpha", "sigma"), transform = list(sigma = "log"), shape = 23)

mcmc_scatter_default_shape mcmc_scatter_23_shape

Similarly, users can control the shapes of their main points when they have divergent points.

library(rstanarm)
fit <- stan_glm(
     mpg ~ ., data = mtcars,
     iter = 1000, refresh = 0,
     # this combo of prior and adapt_delta should lead to some divergences
     prior = hs(),
     adapt_delta = 0.9
)

posterior <- as.array(fit)
np <- nuts_params(fit)

mcmc_scatter(posterior, pars = c("wt", "sigma"), np = np)
mcmc_scatter(posterior, pars = c("wt", "sigma"), np = np, shape=25)

mcmc_scatter_div_default_shape mcmc_scatter_div_25_shape

div_style <- scatter_style_np(div_color = "green", div_shape = 4, div_size = 4)

mcmc_scatter(posterior, pars = c("sigma", "(Intercept)"), np = np, np_style = div_style)
mcmc_scatter(posterior, pars = c("sigma", "(Intercept)"), np = np, np_style = div_style, shape=22)

mcmc_scatter_custom_div_default_shape mcmc_scatter_custom_div_22_shape

@behramulukir behramulukir marked this pull request as ready for review September 6, 2025 15:35
@behramulukir behramulukir changed the title add shape parameter to mcmc_scatter add shape argument to mcmc_scatter Sep 6, 2025
@behramulukir behramulukir self-assigned this Sep 6, 2025
@avehtari
Copy link
Member

avehtari commented Sep 7, 2025

Looks good, and I tested that it worked in my use case

@behramulukir
Copy link
Collaborator Author

Great then! I'll see what's going wrong with the tests and finish this PR

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.66%. Comparing base (89fea18) to head (b4866e3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #375      +/-   ##
==========================================
+ Coverage   98.62%   98.66%   +0.03%     
==========================================
  Files          35       35              
  Lines        5748     5749       +1     
==========================================
+ Hits         5669     5672       +3     
+ Misses         79       77       -2     

☔ 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.

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

Great, thanks @behramulukir. Everything looks good, so I'll go ahead and merge it now.

@jgabry jgabry merged commit fcb73c9 into master Sep 8, 2025
6 checks passed
@jgabry jgabry deleted the mcmc_scatter-shape branch September 8, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants