easystats / bayestestR

:ghost: Utilities for analyzing Bayesian models and posterior distributions
https://easystats.github.io/bayestestR/
GNU General Public License v3.0
563 stars 55 forks source link

ROPE range defaults to [-0.1,0.1] instead of '0 +/- .1 * sd(y)' for stan_glm in describe_posterior #589

Closed strengejacke closed 1 year ago

strengejacke commented 1 year ago

Fixes #587

strengejacke commented 1 year ago
library(rstanarm)
d <- data.frame(
  y = c(
    7, 38, 6, 11, 0, 8, 6, 5, 28, 2, 32, 14,
    46, 19, 20, 28, 51, 12, 10, 1, 2, 22
  ),
  x = c(
    46, 41, 30, 30, 61, 42, 63, 13, 52, 59, 42, 45,
    55, 47, 36, 48, 70, 67, 50, 34, 72, 46
  )
)
m <- stan_glm(y ~ x, data = d)
bayestestR::describe_posterior(m)
#> Summary of Posterior Distribution
#> 
#> Parameter   | Median |          95% CI |     pd |          ROPE | % in ROPE |  Rhat |     ESS
#> ---------------------------------------------------------------------------------------------
#> (Intercept) |   9.00 | [-15.60, 33.02] | 77.55% | [-1.48, 1.48] |     7.29% | 1.000 | 3213.00
#> x           |   0.16 | [ -0.32,  0.66] | 76.02% | [-1.48, 1.48] |      100% | 1.000 | 3240.00

Created on 2023-03-14 with reprex v2.0.2

mattansb commented 1 year ago

What was this doing before?

strengejacke commented 1 year ago

It was working several months ago, but then Vincent and I came up with a performance improvement by converting model objects to data frames only once (https://github.com/easystats/bayestestR/pull/532). However, in .describe_posterior(), instead of model objects, a data frame of posteriors was passed to every function (like pd(), rope() etc.). This works well in most situations, except when you want to define the rope range. This PR fixes this issue

strengejacke commented 1 year ago

errors seem unrelated