-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better emmeans outputs #672
Conversation
This might break somethings in |
Do you have an example what might be broken in see? @IndrajeetPatil have you already submitted see? |
No, not yet. Should I wait? |
I'll get some non-working examples tomorrow. |
Yeah, maybe we can already take the forthcoming bayestestR changes into account, and submit bayestestR after see. |
SGTM. |
Alright, going off of https://easystats.github.io/see/articles/bayestestR.html, we have: library(bayestestR)
library(emmeans)
library(insight)
library(rstanarm)
mod <- stan_glm(mpg ~ hp + factor(cyl), data = mtcars, refresh = 0)
modp <- unupdate(mod)
#> Sampling priors, please wait...
em1 <- emmeans(mod, ~ cyl | hp, at = list(hp = c(50, 100))) Plots that workresult <- point_estimate(em1)
plot(result) result <- rope(em1)
plot(result) result <- bayesfactor_parameters(em1, prior = modp)
#> Warning: Bayes factors might not be precise.
#> For precise Bayes factors, sampling at least 40,000 posterior samples is
#> recommended.
plot(result) Plots that don't fail but are wrong:
result <- si(em1, prior = modp)
#> Warning: Support intervals might not be precise.
#> For precise support intervals, sampling at least 40,000 posterior
#> samples is recommended.
plot(result)
result <- estimate_density(em1)
plot(result) Plots that error
result <- describe_posterior(em1)
plot(result)
#> Error in `scale_y_continuous()`:
#> ! Discrete values supplied to continuous scale.
#> ℹ Example values: Distribution, Distribution, Distribution, Distribution, and
#> Distribution
result <- p_direction(em1)
plot(result)
#> Error in do.call(rbind, by(dataplot, list(dataplot$y, dataplot$fill), : second argument must be a list
result <- p_significance(em1)
plot(result)
#> Error in do.call(rbind, by(dataplot, list(dataplot$y, dataplot$fill), : second argument must be a list
result <- hdi(em1)
plot(result)
#> Error in `ggridges::geom_ridgeline_gradient()`:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `.data$x`:
#> ! Column `x` not found in `.data`.
result <- equivalence_test(em1)
plot(result)
#> Error in `[.emmGrid`(data, , i$Parameter, drop = FALSE): argument "i" is missing, with no default Created on 2024-09-03 with reprex v2.1.0 |
|
ok, insight was just updated one or two days ago... What would you suggest? Release see as planned, and keep this for the next update round? |
I opened a PR (easystats/see#360) for testing purposes, to see if the current changes in insight and this PR break see or not. |
I think we can merge to be sent to CRAN on the next round of updates (I will also make a similar PR here for |
Added most of the support for library(bayestestR)
library(marginaleffects)
#> Warning: package 'marginaleffects' was built under R version 4.3.3 library(insight)
library(rstanarm)
#> Loading required package: Rcpp
#> This is rstanarm version 2.32.1
#> - See https://mc-stan.org/rstanarm/articles/priors for changes to default priors!
#> - Default priors may change, so it's safest to specify priors, even if equivalent to the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores()) mod <- stan_glm(mpg ~ hp + factor(cyl), data = mtcars, refresh = 0)
modp <- unupdate(mod)
#> Sampling priors, please wait... em1 <- avg_predictions(mod, variables = list("cyl" = unique, hp = c(50, 100)))
point_estimate(em1)
#> Point Estimate
#>
#> cyl | hp | Median | Mean | MAP
#> -------------------------------------
#> 4 | 50.00 | 27.41 | 27.43 | 27.34
#> 4 | 100.00 | 26.23 | 26.23 | 26.20
#> 6 | 50.00 | 21.51 | 21.52 | 21.58
#> 6 | 100.00 | 20.32 | 20.33 | 20.34
#> 8 | 50.00 | 18.88 | 18.93 | 19.12
#> 8 | 100.00 | 17.70 | 17.73 | 17.10 map_estimate(em1)
#> MAP Estimate
#>
#> cyl | hp | MAP_Estimate
#> ---------------------------
#> 4 | 50.00 | 27.34
#> 4 | 100.00 | 26.20
#> 6 | 50.00 | 21.58
#> 6 | 100.00 | 20.34
#> 8 | 50.00 | 19.12
#> 8 | 100.00 | 17.10 eti(em1)
#> Equal-Tailed Interval
#>
#> cyl | hp | 95% ETI
#> -----------------------------
#> 4 | 50.00 | [25.20, 29.69]
#> 4 | 100.00 | [24.18, 28.18]
#> 6 | 50.00 | [18.26, 24.88]
#> 6 | 100.00 | [17.80, 22.94]
#> 8 | 50.00 | [13.79, 24.29]
#> 8 | 100.00 | [14.01, 21.60] hdi(em1)
#> Highest Density Interval
#>
#> cyl | hp | 95% HDI
#> -----------------------------
#> 4 | 50.00 | [25.16, 29.60]
#> 4 | 100.00 | [24.18, 28.18]
#> 6 | 50.00 | [18.34, 24.94]
#> 6 | 100.00 | [17.73, 22.83]
#> 8 | 50.00 | [14.13, 24.50]
#> 8 | 100.00 | [14.16, 21.71] ci(em1)
#> Equal-Tailed Interval
#>
#> cyl | hp | 95% ETI
#> -----------------------------
#> 4 | 50.00 | [25.20, 29.69]
#> 4 | 100.00 | [24.18, 28.18]
#> 6 | 50.00 | [18.26, 24.88]
#> 6 | 100.00 | [17.80, 22.94]
#> 8 | 50.00 | [13.79, 24.29]
#> 8 | 100.00 | [14.01, 21.60] bci(em1)
#> cyl hp CI CI_low CI_high
#> 1 4 50 0.95 25.22676 29.74384
#> 2 4 100 0.95 24.16353 28.17122
#> 3 6 50 0.95 18.29945 24.89895
#> 4 6 100 0.95 17.81465 22.97405
#> 5 8 50 0.95 13.93223 24.39837
#> 6 8 100 0.95 14.12260 21.66458 spi(em1)
#> Shortest Probability Interval
#>
#> cyl | hp | 95% SPI
#> -----------------------------
#> 4 | 50.00 | [25.16, 29.60]
#> 4 | 100.00 | [24.18, 28.18]
#> 6 | 50.00 | [18.34, 24.94]
#> 6 | 100.00 | [17.72, 22.83]
#> 8 | 50.00 | [14.12, 24.50]
#> 8 | 100.00 | [14.12, 21.67] p_rope(em1)
#> Proportion of samples inside the ROPE [-0.10, 0.10]
#>
#> cyl | hp | p (ROPE)
#> -----------------------
#> 4 | 50.00 | < .001
#> 4 | 100.00 | < .001
#> 6 | 50.00 | < .001
#> 6 | 100.00 | < .001
#> 8 | 50.00 | < .001
#> 8 | 100.00 | < .001 p_map(em1)
#> MAP-based p-value
#>
#> cyl | hp | p (MAP)
#> ----------------------
#> 4 | 50.00 | < .001
#> 4 | 100.00 | < .001
#> 6 | 50.00 | < .001
#> 6 | 100.00 | < .001
#> 8 | 50.00 | < .001
#> 8 | 100.00 | < .001 p_direction(em1)
#> Probability of Direction
#>
#> cyl | hp | pd
#> -------------------
#> 4 | 50.00 | 100%
#> 4 | 100.00 | 100%
#> 6 | 50.00 | 100%
#> 6 | 100.00 | 100%
#> 8 | 50.00 | 100%
#> 8 | 100.00 | 100% p_significance(em1)
#> Practical Significance (threshold: 0.10)
#>
#> cyl | hp | ps
#> -------------------
#> 4 | 50.00 | 1.00
#> 4 | 100.00 | 1.00
#> 6 | 50.00 | 1.00
#> 6 | 100.00 | 1.00
#> 8 | 50.00 | 1.00
#> 8 | 100.00 | 1.00 rope(em1)
#> # Proportion of samples inside the ROPE [-0.10, 0.10]:
#>
#> cyl | hp | inside ROPE
#> -----------------------
#> 4 | 50 | 0.00 %
#> 4 | 100 | 0.00 %
#> 6 | 50 | 0.00 %
#> 6 | 100 | 0.00 %
#> 8 | 50 | 0.00 %
#> 8 | 100 | 0.00 % equivalence_test(em1)
#> # Test for Practical Equivalence
#>
#> ROPE: [-0.10 0.10]
#>
#> cyl | hp | H0 | inside ROPE | 95% HDI
#> --------------------------------------------------
#> 4 | 50 | Rejected | 0.00 % | [25.20 29.69]
#> 4 | 100 | Rejected | 0.00 % | [24.18 28.18]
#> 6 | 50 | Rejected | 0.00 % | [18.26 24.88]
#> 6 | 100 | Rejected | 0.00 % | [17.80 22.94]
#> 8 | 50 | Rejected | 0.00 % | [13.79 24.29]
#> 8 | 100 | Rejected | 0.00 % | [14.01 21.60] Created on 2024-09-03 with reprex v2.1.0 To do:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #672 +/- ##
==========================================
- Coverage 52.45% 52.19% -0.27%
==========================================
Files 65 65
Lines 5309 5539 +230
==========================================
+ Hits 2785 2891 +106
- Misses 2524 2648 +124 ☔ View full report in Codecov by Sentry. |
Alright, I'm done! |
ok, so everything works except plot-methods, right? |
Yup. Just one last thing to change and then I'll merge. |
are the latest changes in insight only required for plotting, or in general for emmeans/marginaleffects support? |
They are fundamental for this PR in general. |
Closes #661, #670
Created on 2024-09-03 with reprex v2.1.0