Skip to content

Removed soft-deprecated code from posterior_vs_prior. - #658

Open
tjmckinley wants to merge 5 commits into
stan-dev:masterfrom
tjmckinley:fixWarning
Open

tjmckinley wants to merge 5 commits into
stan-dev:masterfrom
tjmckinley:fixWarning

Conversation

@tjmckinley

Copy link
Copy Markdown

Hi,

Thanks for developing rstanarm, it's made teaching Bayesian methods far easier and more accessible! I noticed a warning when running the posterior_vs_prior() function for more recent updates of tidyverse packages, because it relies on some soft-deprecated functions. A reprex is below:

## load libraries
library(rstanarm)

## set up data
dat <- data.frame(y = 8)

## fit binomial model
p_bayes <- stan_glm(
    cbind(y, 10 - y) ~ 1, 
    data = dat, 
    family = binomial(link = "logit"),
    prior_intercept = normal(0, 1.5)
  )

## compare 90% credible intervals for the prior and posterior
posterior_vs_prior(p_bayes, pars = "(Intercept)")

This returns:

Warning messages:
1: `aes_string()` was deprecated in ggplot2 3.0.0.
ℹ Please use tidy evaluation idioms with `aes()`.
ℹ See also `vignette("ggplot2-in-packages")` for more information.
ℹ The deprecated feature was likely used in the rstanarm package.
  Please report the issue at <https://github.com/stan-dev/rstanarm/issues>. 
2: The `size` argument of `grid_lines()` is deprecated as of bayesplot 1.16.0.
ℹ Please use the `linewidth` argument instead.
ℹ The deprecated feature was likely used in the rstanarm package.
  Please report the issue at <https://github.com/stan-dev/rstanarm/issues>. 

This PR contains a possible fix utilising rlang, which is a dependency of ggplot2, which itself is a dependency of rstanarm, so hopefully this should work without any further changes. Not sure if this is useful, but the code is here if it is. It seems to fix the problems for me.

Cheers,

TJ

@jgabry

jgabry commented Sep 21, 2026

Copy link
Copy Markdown
Member

Thanks for developing rstanarm, it's made teaching Bayesian methods far easier and more accessible!

Thanks for the PR and for this comment. That was our goal when we developed the package!

Looking at your PR made me realize we have other deprecated ggplot2 syntax that we need to clean up so I'm going to push a few commits to this before merging.

@bgoodri while fixing deprecated ggplot2 syntax I also fixed a bug in plot_nonlinear so that it can now plot bivariate smooths from a model with more than one smooth term without an error.

Plotting a bivariate smooth from a model with more than one smooth term either errored or silently used the wrong variables:

- `sapply()` returned a list or matrix for `xnames` (depending on the
  mix of smooth dimensions) and only the vector case was handled.
- `fs` and `xnames` were subset by a logical the length of `smooths`
  rather than `labels`, so the first smooth's variables were always
  used regardless of which one was selected.
- `nd` was resampled with indices up to `nrow(xz)` (10000) rather than
  `nrow(nd)`, producing NA rows and a NaN surface whenever the model
  had other covariates.
- The bivariate check was model-wide (`!any(fs)`), so any `bs = "fs"`
  smooth sent bivariate smooths down the univariate path.
@tjmckinley

Copy link
Copy Markdown
Author

Awesome. Glad this was useful. Thanks again for the package.

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.

2 participants