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

including p-values in customized output omits random effects from mixed models #494

Closed
strengejacke opened this issue Jun 7, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@strengejacke
Copy link

model <- lme4::lmer(Sepal.Width ~ Petal.Length + (1|Species), data = iris)
modelsummary::modelsummary(model, estimate  = "{estimate} [{conf.low}, {conf.high}] {p.value}", statistic = NULL, fmt = 2)

Current output:
image

It would be great to keep the random effects, and just set blank fields for p-values in the random effects rows.

@strengejacke strengejacke added the bug Something isn't working label Jun 7, 2022
@vincentarelbundock
Copy link
Owner

Thanks for reporting! I don’t use mixed-effects models often, so these are very useful test cases.

Should be fixed in 0959b02

Note that user-input in glue strings is totally arbitrary, so my current checks won’t catch every possibility, but it should be a considerable improvement.

library(lme4)
library(modelsummary)
model <- lmer(Sepal.Width ~ Petal.Length + (1|Species), data = iris)
modelsummary(model,
    "markdown",
    estimate  = "{estimate} [{conf.low}, {conf.high}] {p.value}",
    statistic = NULL)
Model 1
(Intercept) 1.998 [0.888, 3.109] 0.001
Petal.Length 0.282 [0.165, 0.399] 0.000
SD (Intercept Species) 0.892
SD (Observations) 0.316
Num.Obs. 150
RMSE 0.31

@strengejacke
Copy link
Author

Nice, thanks!

@strengejacke
Copy link
Author

I'm re-opening it, because it doesn't fully work when CIs are only partially available, see:

m1 <- lme4::lmer(Sepal.Width ~ Petal.Length + (1|Species), data = iris)
m2 <- lme4::lmer(Sepal.Width ~ Petal.Length + (1 + Petal.Length |Species), data = iris)
m3 <- lme4::lmer(Sepal.Width ~ Petal.Length + Petal.Width + (1 + Petal.Length |Species), data = iris)
#> boundary (singular) fit: see help('isSingular')
parameters::compare_models(m1, m2, m3, effects = "all")
#> Your model may suffer from singularity (see '?lme4::isSingular' and
#>   '?performance::check_singularity').
#>   Some of the standard errors and confidence intervals of the random
#>   effects parameters are probably not meaningful!
#> Parameter                    |                m1 |                     m2 |                    m3
#> -------------------------------------------------------------------------------------------------
#> (Intercept)                  | 2.00 (0.89, 3.11) | 1.99 ( 0.89,     3.10) | 1.76 (0.44,     3.08)
#> Petal Length                 | 0.28 (0.16, 0.40) | 0.29 ( 0.16,     0.41) | 0.16 (0.03,     0.29)
#> SD (Intercept)               | 0.89 (0.33, 2.43) | 0.88 ( 0.27,     2.87) | 1.10 (0.36,     3.30)
#> SD (Observations)            | 0.32 (0.28, 0.35) | 0.32 ( 0.28,     0.35) | 0.30 (0.26,     0.33)
#> SD (Petal.Length)            |                   | 0.02 ( 0.00, 1.76e+07) | 0.03 (0.00, 2.33e+05)
#> Cor (Intercept~Petal.Length) |                   | 0.19 (-1.00,     1.00) | 1.00 (    ,     1.00)
#> Petal Width                  |                   |                        | 0.61 (0.34,     0.88)
#> -------------------------------------------------------------------------------------------------
#> Observations                 |               150 |                    150 |                   150

Created on 2022-06-08 by the reprex package (v2.0.1)

In this case, the following code produces following table:

modelsummary::modelsummary(model, estimate  = "{estimate} [{conf.low}, {conf.high}]", 
                           shape = group + term + statistic ~ model,
                           statistic = NULL, fmt = 2)

image

Note the message from compare_parameters() (requires this PR to work, I think).

@strengejacke strengejacke reopened this Jun 8, 2022
@vincentarelbundock
Copy link
Owner

Is this working as you expected with the latest commits?

library(modelsummary)
models <- list(
    lme4::lmer(Sepal.Width ~ Petal.Length + (1|Species), data = iris),
    lme4::lmer(Sepal.Width ~ Petal.Length + (1 + Petal.Length |Species), data = iris),
    lme4::lmer(Sepal.Width ~ Petal.Length + Petal.Width + (1 + Petal.Length |Species), data = iris))
modelsummary(
    models,
    estimate = "{estimate} [{conf.low}, {conf.high}]",
    statistic = NULL,
    gof_map = NA,
    output = "markdown")
Model 1 Model 2 Model 3
(Intercept) 1.998 [0.888, 3.109] 1.993 [0.890, 3.096] 1.762 [0.439, 3.084]
Petal.Length 0.282 [0.165, 0.399] 0.286 [0.164, 0.408] 0.160 [0.027, 0.292]
Petal.Width 0.610 [0.341, 0.878]
SD (Intercept Species) 0.892 [0.328, 2.430] 0.885 [0.273, 2.866] 1.096 [0.364, 3.300]
SD (Petal.Length Species) 0.024 [0.000, 17569330.944] 0.026 [0.000, 232874.419]
Cor (Intercept~Petal.Length Species) 0.189 [-1.000, 1.000] 1.000 [, 1.000]
SD (Observations) 0.316 [0.281, 0.354] 0.315 [0.281, 0.354] 0.296 [0.264, 0.332]

Created on 2022-06-08 by the reprex package (v2.0.1)

@vincentarelbundock
Copy link
Owner

Preparing a Ripley-induced emergency release, so closing all the issues which seem (to me) complete. Feel free to re-open or keep the discussion going if you see a need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants