Skip to content
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

estimate_means() : option for prediction interval/include sigma #146

Open
bwiernik opened this issue Sep 8, 2021 · 5 comments
Open

estimate_means() : option for prediction interval/include sigma #146

bwiernik opened this issue Sep 8, 2021 · 5 comments

Comments

@bwiernik
Copy link
Contributor

bwiernik commented Sep 8, 2021

I'd like to be able to make this plot, visualizing a discrete predictor, with estimated group means and prediction intervals. I'd also like to include densities.

library(see)
dat_mtcars <- transform(mtcars, am = factor(am))
m <- lm(mpg ~ am, data = dat_mtcars)
modelbased::estimate_means(m, at = "am") |> plot() + ggdist::stat_dist_halfeye(ggplot2::aes(x = am, dist = distributional::dist_normal(Mean, sqrt(SE^2 + sigma(m)^2)), fill = am), alpha = .5, width = .2) + see::theme_modern() + ggplot2::guides(fill = "none")

Created on 2021-09-08 by the reprex package (v2.0.1)

To accomplish this, we would need two changes:

  1. Add option to estimate_means() for prediction intervals
  2. Add option to include densities to estimate means / estimate_prediction family with discrete x
@DominiqueMakowski
Copy link
Member

for means violins do work asshowninthedocs ^^:

m <- modelbased::estimate_means(lm(mpg ~ am, data = dplyr::mutate(mtcars, am = as.factor(am))))
#> We selected `at = c("am")`.
plot(m, show_data = c("violin", "boxplot", "jitter"))

plot(m, show_data = c("violin", "jitter"), 
     violin = list(aes = list(fill = "am")))

Created on 2021-09-09 by the reprex package (v2.0.1)

We don't support half violins though, but it can easily be added by adding its support to see::geom_from_list(). But then again, my thought is that default plotting is just that; default plotting for quick and convenient explorations. If people want better plots for publications and all, they should make them because we cannot cater for all preferences (and this is why we also can provide the RECIPE of the ggplot so that people can reproduce the plot and then tweak it to their wildest desires 💪).

Then about prediction intervals, if emmeans supports it then we do too via the kwargs, the question is wether to eventually expose the argument? If you meat by that tweaking only the dist aesthetic of ggdist::stat_dist_halfeye, then it falls back to supporting ggdist' geoms in see::geom_from_list()

@mattansb
Copy link
Member

mattansb commented Sep 9, 2021

Didn't we write a whole function of getting prediction intervals?

@DominiqueMakowski
Copy link
Member

yes for estimate_predicted that works, but estimate_means relies on emmeans

@bwiernik
Copy link
Contributor Author

bwiernik commented Sep 9, 2021

The solution here might be to resolve #145

@strengejacke
Copy link
Member

There is a way to do this in emmeans, I think

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

No branches or pull requests

4 participants