strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
603 stars 91 forks source link

Use mice mipo/data.frame object with sjPlot tab_model #800

Open lianntucker opened 2 years ago

lianntucker commented 2 years ago

This may be for potential enhancements of the package, but as far as I can tell there isn't a way to pass a mipo/data.frame object from mice to tab_model.

I'm trying to get a table output for a pooled logistic model with imputed datasets from mice so I can see and report the standardized and exponentiated estimates and model fit statistics, but it seems like tab_model will not take a mipo/data.frame object that comes from analyzing pooled data.

Here is an example with the trial dataset from the survival package.

library(survival)
library(tidyverse)
library(mice)
library(sjPlot)

suppressWarnings(mice::mice(trial, m = 2)) %>%
                with(glm(death ~ marker + grade, family = "binomial")) %>% 
                pool() %>%
                tab_model(., show.se = TRUE, show.std = TRUE, show.aic = TRUE)

This give me this error:

Error in if (fam.info$is_linear) transform <- NULL else transform <- "exp" : 
  argument is of length zero
jrcalabrese commented 2 years ago

I am also interested in using tab_model to create regression tables for mipo objects. I have been trying to create regression tables for linear models but I get the error message, invalid 'x' type in 'x || y'.

library(tidyverse)
library(sjPlot)
library(mice)
set.seed(123)

data(nhanes)
imp <- mice(nhanes, m=3, print=FALSE)
with(imp, lm(age ~ bmi + chl)) %>% 
  pool() %>% 
  tab_model(.)
#> Error in fam.info$is_linear || identical(fam.info$link_function, "identity"): invalid 'x' type in 'x || y'

Alternatively, pooling results within tab_model prints multiple tables, depending on the number of imputations, but also gives a warning message about a deprecated function from sjstats.

# creates multiple tables
data(nhanes)
imp <- mice(nhanes, m=3, print=FALSE)
mod <- with(imp, lm(age ~ bmi + chl))
tab_model(pool(mod)) # This prints 3 tables in the Viewer.
#> 'r2()' does not support models of class 'mipo'.