-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Improve plot() for check_predictions() #290
Comments
library(performance)
library(see)
mtcars$vs2 <- factor(letters[mtcars$vs + 1])
model <- glm(vs2 ~ wt + mpg, data = mtcars, family = "binomial")
plot(check_predictions(model)) plot(check_predictions(model), type = "dots") ## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)
d <- data.frame(treatment, outcome, counts) # showing data
model <- glm(counts ~ outcome + treatment, family = poisson(), data = d)
plot(check_predictions(model)) plot(check_predictions(model), type = "dots") Created on 2023-05-24 with reprex v2.0.2 |
library(performance)
library(see)
library(glmmTMB)
data(Salamanders)
m1 <- glmmTMB(count ~ mined + (1 | site),
zi = ~mined,
family = poisson, data = Salamanders
)
plot(check_predictions(m1)) plot(check_predictions(m1), type = "dots") Created on 2023-05-24 with reprex v2.0.2 |
Maybe this example is quite good to demonstrate why dots can be more useful than lines in some situations: library(performance)
library(see)
set.seed(99)
d <- iris
d$skewed <- rpois(150, 1)
m2 <- glm(skewed ~ Species + Petal.Length + Petal.Width, data = d, family = poisson())
out <- check_predictions(m2)
plot(out) plot(out, type = "dots") Created on 2023-05-24 with reprex v2.0.2 |
Thanks for taking the initiative on this! Really happy to see this added. I like the use of the green dot and thin line rather than the bars for the observed data. It feels more consistent with the density. Comparing the design of the Could we support both? Perhaps have options For all of these options, I think the green line for observed data should be added last to the plot so that it is on top and not obscured by the replication lines/dots. |
The dot plot lacks a legend to clarify which points are "model predictions" and which is the observed one. |
True, why didn't I realize that? 🙄 |
library(performance)
library(see)
set.seed(99)
d <- iris
d$skewed <- rpois(150, 1)
m2 <- glm(skewed ~ Species + Petal.Length + Petal.Width, data = d, family = poisson())
out <- check_predictions(m2)
plot(out)
#> The model has an integer or a categorical response variable.
#> It is recommended to switch to a dot-plot style, e.g.
#> `plot(check_model(model), type = "discrete_dots"`. plot(out, type = "discrete_dots") plot(out, type = "discrete_interval") plot(out, type = "discrete_both") Created on 2023-05-25 with reprex v2.0.2 |
What would you suggest as default for models with integer/ordinal/binary/... outcome? |
See the updated subtitle for intervals: library(performance)
library(see)
set.seed(99)
d <- iris
d$skewed <- rpois(150, 1)
m2 <- glm(skewed ~ Species + Petal.Length + Petal.Width, data = d, family = poisson())
out <- check_predictions(m2)
plot(out, type = "discrete_interval") Created on 2023-05-25 with reprex v2.0.2 |
Maybe simple dots are enough for the observed data points? library(performance)
library(see)
set.seed(99)
d <- iris
d$skewed <- rpois(150, 1)
m2 <- glm(skewed ~ Species + Petal.Length + Petal.Width, data = d, family = poisson())
out <- check_predictions(m2)
plot(out)
#> The model has an integer or a categorical response variable.
#> It is recommended to switch to a dot-plot style, e.g.
#> `plot(check_model(model), type = "discrete_dots"`. plot(out, type = "discrete_dots") plot(out, type = "discrete_interval") plot(out, type = "discrete_both") Created on 2023-05-25 with reprex v2.0.2 |
library(performance)
library(see)
set.seed(99)
d <- iris
d$skewed <- rpois(150, 1)
m2 <- glm(skewed ~ Species + Petal.Length + Petal.Width, data = d, family = poisson())
out <- check_predictions(m2)
plot(out) + theme_blackboard()
#> The model has an integer or a categorical response variable.
#> It is recommended to switch to a dot-plot style, e.g.
#> `plot(check_model(model), type = "discrete_dots"`. plot(out, type = "discrete_dots") + theme_blackboard() plot(out, type = "discrete_interval") + theme_blackboard() plot(out, type = "discrete_both") + theme_blackboard() Created on 2023-05-25 with reprex v2.0.2 |
For models with integer/categorical outcomes, we could use bars instead of density lines, like in:
https://solomonkurz.netlify.app/blog/2023-05-21-causal-inference-with-ordinal-regression/
The text was updated successfully, but these errors were encountered: