Created
May 14, 2024 07:26
-
-
Save ABohynDOE/a8dc039bc7dd4a1ecb7f1aecf9d8c1f1 to your computer and use it in GitHub Desktop.
Two different ways of pooling a list of models fitted on imputed data and then generating a summary table of the model using ´tbl_regression´
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(mice) | |
| library(gtsummary) | |
| # impute the data | |
| df_imputed <- mice::mice(trial, m = 2, seed = 123) | |
| # build the model list | |
| imputed_model_list <- purrr::map( | |
| 1:df_imputed$m, | |
| ~ lm(age ~ marker + grade, complete(df_imputed, .x)) | |
| ) %>% | |
| as.mira() | |
| # present beautiful table with gtsummary | |
| tbl_regression(imputed_model_list) | |
| # build the model using `with` | |
| imputed_model <- with(df_imputed, lm(age ~ marker + grade)) | |
| # present beautiful table with gtsummary | |
| tbl_regression(imputed_model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment