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

Issue plotting lme4 random effects from model_parameters #365

Closed
DanSimonet opened this issue Sep 27, 2024 · 2 comments · Fixed by #366
Closed

Issue plotting lme4 random effects from model_parameters #365

DanSimonet opened this issue Sep 27, 2024 · 2 comments · Fixed by #366
Assignees

Comments

@DanSimonet
Copy link

DanSimonet commented Sep 27, 2024

Amazing suite of packages! I was hoping to pivot my entire mixed modeling workflow to easystats but came across an issue in how model_parameters extracts parameter labels (I believe from broom.mixed) which prevents plotting of group-specific random effects. I am expecting output similar to sjPlot and use this as comparison.

Model

library(lme4)
s_mod <- lmer(Reaction ~ Days + (Days|Subject), data = sleepstudy)

Expectation

# Sjplot output
sjPlot::plot_model(s_mod, show.values = T, type = "re", value.offset = 0.5)

image

Model Parameter + See Result

# Parameters -> see output
parameters::model_parameters(s_mod, group_level = TRUE) |> plot()

image

Source
The problem I believe is broom.mixed::tidy returns term and level as different columns. model_parameters as a result has a single value for the grouping variable in the Parameter column as opposed to the group-specific identifiers which show up in Level.

@strengejacke
Copy link
Member

I think it's because we just haven't a proper plot() method for random effects when group_level = TRUE. Let me check.

@strengejacke
Copy link
Member

Rendering is not perfect here, but these are the options:

library(lme4)
#> Loading required package: Matrix
s_mod <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy)

parameters::model_parameters(s_mod, group_level = TRUE) |>
  plot()

parameters::model_parameters(s_mod, group_level = TRUE) |>
  plot(show_labels = TRUE)

parameters::model_parameters(s_mod, group_level = TRUE) |>
  plot(show_labels = TRUE, size_text = 5)

parameters::model_parameters(s_mod, group_level = TRUE) |>
  plot(sort = "ascending", show_labels = TRUE)

parameters::model_parameters(s_mod, group_level = TRUE) |>
  plot(sort = "ascending", show_labels = TRUE, n_columns = 2)

parameters::model_parameters(s_mod, group_level = TRUE) |>
  plot(sort = "ascending", show_labels = TRUE, show_intercept = FALSE)

Created on 2024-09-27 with reprex v2.1.1

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

Successfully merging a pull request may close this issue.

2 participants