Closed DominiqueMakowski closed 1 year ago
Haha I was looking for that in 'see' !
Wait no but actually I want to replicate the rstanarm thing for Bayesian models:
m <- rstanarm::stan_glm(mpg ~ am, data=mtcars, refresh=0)
performance::posterior_predictive_check(m)
#> Warning in rnorm(ntot, sd = sqrt(vars)): NAs produced
#> Error in if (min(replicated) > min(original)) {: missing value where TRUE/FALSE needed
Created on 2021-02-23 by the reprex package (v0.3.0)
@strengejacke, should we have two versions of it, namely pp_check()
and check_prediction_distribution()
pp_check
is from stan, but the other one would return our version (rather than the one using the default aesthetic of rstan)library(ggplot2)
library(bayestestR)
#> Note: The default CI width (currently `ci=0.89`) might change in future versions (see https://github.com/easystats/bayestestR/discussions/250). To prevent any issues, please set it explicitly when using bayestestR functions, via the 'ci' argument.
model <- rstanarm::stan_glm(mpg ~ am, data=mtcars, refresh=0)
pred <- as.data.frame(insight::get_predicted(model, ci_type = "prediction"))
data_density <- estimate_density(pred, precision = 100)
ggplot(data_density, aes(x = x, y = y)) +
geom_line(aes(group = Parameter), alpha=0.01) +
geom_line(data= estimate_density(insight::get_response(model)), color="red", size=2) +
scale_y_continuous(expand = c(0, 0)) +
see::theme_modern()
Created on 2021-02-23 by the reprex package (v0.3.0)
Wait no but actually I want to replicate the rstanarm thing for Bayesian models:
Yeah, but I did this for freq. models, because for Bayesian models it's already available?
For Bayesian models, pp_check is from stan, but the other one would return our version (rather than the one using the default aesthetic of rstan)
What would be the difference?
our version is more beautiful? ๐ + we can add more info like a title? + it gives a unified output for freq and bayesian (same colors, etc)
ok, got it.
Also, our pp_check is currently not defined for brmsfit objects :(, and for complex models the brms/rstantools version fails:
of course it's not defined for stan models, as those methods are in rstan/rstanrm/brms. I didn't want to overwrite them.
will close soon
๐คจ
oops, i got a bit ahead of myself back then
our version is more beautiful? ๐ + we can add more info like a title? + it gives a unified output for freq and bayesian (same colors, etc)
Could we change to something other than red for the MLE line? Blue or green are more colorblind accessible on top of the black posterior lines.
of course it's not defined for stan models, as those methods are in rstan/rstanrm/brms. I didn't want to overwrite them.
One option might be to define a see print/plot method for them to apply consistent theming without overwriting the core method.
@bwiernik That was just a quick sketch from @DominiqueMakowski. Our current implementation (only for frequentist) already has a blue line on gray lines: https://easystats.github.io/see/articles/performance.html#posterior-predictive-checks
Closing in favor of #477
Opening this for myself, will close soon
Created on 2021-02-22 by the reprex package (v0.3.0)
pred <- as.data.frame(insight::get_predicted(m))