Skip to content

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

Open

Description

@bwiernik

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

Activity

  1. DominiqueMakowski commented on Sep 9, 2021

    @DominiqueMakowski
    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()

  2. mattansb commented on Sep 9, 2021

    @mattansb
    Member

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

  3. DominiqueMakowski commented on Sep 9, 2021

    @DominiqueMakowski
    Member

    yes for estimate_predicted that works, but estimate_means relies on emmeans

  4. bwiernik commented on Sep 9, 2021

    @bwiernik
    ContributorAuthor

    The solution here might be to resolve #145

  5. strengejacke commented on Sep 10, 2021

    @strengejacke
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions