Giter VIP home page Giter VIP logo

Comments (19)

mattansb avatar mattansb commented on May 17, 2024 1

Or plot multiple CIs one on top of each other?
See how something similar is now done in emmeans here.

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

The only edge case that I see is in the case of multiple CIs, but we can easily detect that by checking the length of ci which is stored in the parameters' attributes, and if length > 1 then pass the whole parameter table to the new reshape_ci function, and then simply add the CI as a facet... easy peasy

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

Yup, if tastefully implemented it could be nice

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

(tastefully = in a readable and aesthetically pleasing fashion ^^)

from see.

strengejacke avatar strengejacke commented on May 17, 2024

if tastefully implemented it could be nice

Like in sjPlot?

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

I don't know, does sjPlot handle multiple CIs 😬 ?

Also, by default, I very strongly favour geom_pointrange over error bars (i.e., I find simple lines ------x------, as opposed to brackets ][------x------][, sleeker) ☺️

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

@strengejacke I have misread your link, sjPlot also uses pointrange by default and sort-of boxplots to handle 2 different CIs for is that correct?

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

But yes, sjPlot is tasteful ^^

Nevertheless, it would be good to deal with multiple CIs in an automatic and systemic way

from see.

strengejacke avatar strengejacke commented on May 17, 2024

For Bayesian models, two HDIs are plotted by default:

image

I use geom_errorbar(), but you can use the width-argument to remove the "brackets" from the line-ends.

from see.

strengejacke avatar strengejacke commented on May 17, 2024

Oh, we need to have information about the link-function (as atribute?), in order to choose the correct scale (see again https://strengejacke.github.io/sjPlot/articles/plot_model_estimates.html).

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

For model parameters? Why the link? It's always identity for model_parameters isn't it

from see.

strengejacke avatar strengejacke commented on May 17, 2024

Ok, I probably was thinking a bit too far ahead... Usually, in social science, you would rather want to present (e.g.) Odds or Incidence Rate Ratios instead of log-estimates.

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

We can add this feature in the future for sure

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

The plot might also benefit from the clean_names attributes (currently used by parameters_table).

Note to myself: as matter of fact, format_parameters() might be improved to deal with cases of s(x), poly(x) and bs(x).

from see.

strengejacke avatar strengejacke commented on May 17, 2024

This looks also nice, a "completely" different style...

EAG_nVLXoAE-ckN

from see.

strengejacke avatar strengejacke commented on May 17, 2024

Quick sketch:

library(ggplot2)
library(parameters)

model <- lm(mpg ~ wt + cyl + gear + hp, data = mtcars)
mp <- model_parameters(model, standardize = "refit")

ggplot(mp, aes(x = Parameter, y = Coefficient)) +
  geom_errorbar(aes(ymin = CI_low, ymax = CI_high), alpha = .3, size = 4, width = 0, color = "#2196F3") +
  geom_segment(aes(y = CI_low, yend = CI_low + .4, x = Parameter, xend = Parameter), size = 4, color = "#2196F3", alpha = .5) +
  geom_segment(aes(y = CI_high, yend = CI_high - .4, x = Parameter, xend = Parameter), size = 4, color = "#2196F3", alpha = .5) +
  see::geom_point2(color = "#2196F3", size = 2.5) +
  coord_flip()+
  see::theme_lucid()

Created on 2019-07-26 by the reprex package (v0.3.0)

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

Minimalist is the new maximalist:

library(ggplot2)
library(parameters)

model <- lm(mpg ~ wt + cyl + gear + hp, data = mtcars)
mp <- model_parameters(model, standardize = "refit")

# mp <- mp[mp$Parameter != "(Intercept)", ]
max_value <- max(abs(mp[["Coefficient"]]))

ggplot(mp, aes(x = Parameter, y = Coefficient, color = Coefficient)) +
  geom_hline(aes(yintercept = 0), linetype = "dashed") +
  geom_pointrange(aes(ymin = CI_low, ymax= CI_high), size = 1) +
  scale_color_gradientn(colours = c("red", "orange", "green"), limits=c(-max_value, max_value)) +
  coord_flip() +
  see::theme_modern(legend.position = "none")

Created on 2019-07-26 by the reprex package (v0.3.0)

from see.

DominiqueMakowski avatar DominiqueMakowski commented on May 17, 2024

For Multiple CIs is kinda tough to display it on one plot

library(ggplot2)
library(parameters)
library(rstanarm)

model <- stan_glm(mpg ~ wt + cyl + gear + hp, data = mtcars, refresh = 0)
mp <- model_parameters(model, ci = c(0.5, 0.7, 0.9))
#> Possible multicollinearity between hp and cyl (r = 0.78). This might lead to inappropriate results. See 'Details' in '?rope'.

max_value <- max(abs(mp[["Median"]]))

ggplot(mp, aes(x = Parameter, y = Median, color = Median)) +
  geom_hline(aes(yintercept = 0), linetype = "dashed") +
  geom_pointrange(aes(ymin = CI_low_90, ymax= CI_high_90), size = 0.5) +
  geom_pointrange(aes(ymin = CI_low_70, ymax= CI_high_70), size = 1) +
  geom_pointrange(aes(ymin = CI_low_50, ymax= CI_high_50), size = 2) +
  scale_color_gradientn(colours = c("#f44336", "#FF9800", "#4CAF50"), limits=c(-max_value, max_value)) +
  coord_flip() +
  see::theme_modern(legend.position = "none")

Created on 2019-07-26 by the reprex package (v0.3.0)

from see.

strengejacke avatar strengejacke commented on May 17, 2024

Current implementation:

library(parameters)
library(see)

model <- glm(mpg ~ wt + cyl + gear + hp, data = mtcars)
mp <- model_parameters(model)
plot(mp)

mp <- model_parameters(model, ci = c(0.5, 0.7, 0.9))
plot(mp)

Created on 2019-07-30 by the reprex package (v0.3.0)

from see.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.