Closed Generalized closed 11 months ago
Hi
the provided pooled model data cannot be reproduced as it requires specific package and the m_longit
object.
As I understand it, it is the result of mice::pool()
.
I am not familiar with mice
. I explored quickly the structure of a mipo
object. And I'm not sure if we could do much more:
model.frame()
) which is crucial to identify the different variables and the reference valuesSo, I'm truly sorry, but I do not see how to automatically improve the plot.
However, you can still customize it manually. See below an example.
library(mice)
#>
#> Attachement du package : 'mice'
#> L'objet suivant est masqué depuis 'package:stats':
#>
#> filter
#> Les objets suivants sont masqués depuis 'package:base':
#>
#> cbind, rbind
library(ggstats)
library(tidyverse)
imp <- mice(nhanes2, maxit = 2, m = 2)
#>
#> iter imp variable
#> 1 1 bmi hyp chl
#> 1 2 bmi hyp chl
#> 2 1 bmi hyp chl
#> 2 2 bmi hyp chl
fit <- with(data = imp, exp = lm(bmi ~ hyp + chl + age))
mod <- pool(fit)
# getting the data used by ggcoef_table()
# add exponentiate = TRUE if you want exponentiated values
td <- ggcoef_model(
mod,
return_data = TRUE,
signif_stars = FALSE,
show_p_values = FALSE
)
#> ✖ Unable to identify the list of variables.
#>
#> This is usually due to an error calling `stats::model.frame(x)`or `stats::model.matrix(x)`.
#> It could be the case if that type of model does not implement these methods.
#> Rarely, this error may occur if the model object was created within
#> a functional programming framework (e.g. using `lappy()`, `purrr::map()`, etc.).
# remove intercept
td <- td |> filter(term != "(Intercept)")
# manual recoding
td$variable
#> [1] hypyes chl age40-59 age60-99
#> Levels: (Intercept) hypyes chl age40-59 age60-99
td$variable <- td$variable %>%
fct_recode(
"hyp" = "hypyes",
"age" = "age40-59",
"age" = "age60-99"
)
td$var_label
#> [1] hypyes chl age40-59 age60-99
#> Levels: (Intercept) hypyes chl age40-59 age60-99
td$var_label <- td$var_label %>%
fct_recode(
"Label for hyp" = "hypyes",
"Label for chl" = "chl",
"Label for age" = "age40-59",
"Label for age" = "age60-99"
)
td$label
#> [1] hypyes chl age40-59 age60-99
#> Levels: (Intercept) hypyes chl age40-59 age60-99
td$label <- td$label %>%
fct_recode(
"yes" = "hypyes",
" " = "chl",
"40-49" = "age40-59",
"60-99" = "age60-99"
)
# add exponentiate = TRUE if values are exponentiated
p <- ggcoef_table(
data = td,
y = "label", # indicating the correct col to use for y
table_header = c("EST", "95% CI", "p")
)
# changing x axis label of the left plot
p[[1]] <- p[[1]] + xlab("EST")
p
Created on 2023-08-18 with reprex v2.0.2
That's great answer! With this level of customization I can manually define the "internal" relationships between the elements of interactions, so this will be reflected by appropriate "grouping" on the plot. That's good enough to produce the desired outcome regardless of those issues.
Thank you very much for the illustration!
PS: yes, that's the MICE imputed model, with pooled coefficients over the multiply imputed datasets.
It partially works, but fails to recognize everything. It doesn't recognize odds ratios, doesn't format the coefficients nicely like in the examples.
The model is the GEE estimated logistic regression (geepack::geeglm). There exists a basic tidier:
But the results:
Pooled model data: