gtsummary::tbl_regression 使用 pool_and_tidy_mice() 和 tidy_standardize()

gtsummary::tbl_regression use pool_and_tidy_mice() with tidy_standardize()

我目前正在尝试 运行 tbl_regression 通过逻辑 glm 使用来自 mice 运行 的估算数据集。我在尝试组合自定义 tidiers pool_and_tidy_micetidy_standardize 以便从合并的小鼠结果和标准化优势比估计中获得回归输出时遇到问题。

有没有办法通过 tbl_regression 或我可以采取的其他步骤来获取标准化的比值比?

surival 包为例,我可以使用以下代码获得非估算数据的标准化优势比:

library(tidyverse)
library(broom.mixed)
library(broom)
library(survival)

mod <- glm(death ~ marker + grade, data = trial, family = "binomial")
tbl_regression(mod, tidy_fun = tidy_standardize, 
                    exponentiate = TRUE, conf.int = TRUE, conf.level = 0.95)

但是,如果我尝试在下面的代码中使用 tidy_standardize

suppressWarnings(mice::mice(trial, m = 2)) %>%
  with(glm(death ~ marker + grade, family = "binomial")) %>%
  tbl_regression(tidy_fun = tidy_standardize, 
                 exponentiate = TRUE, conf.int = TRUE, conf.level = 0.95)

我收到这个错误:

x There was an error calling `tidy_fun()`. Most likely, this is because the
function supplied in `tidy_fun=` was misspelled, does not exist, is not
compatible with your object, or was missing necessary arguments (e.g. `conf.level=` or `conf.int=`). See error message below.
Error: Error in .model_parameters_generic(model = mice::pool(model), ci = ci, : formal argument "standardize" matched by multiple actual arguments
In addition: Warning messages:
1: Could not get model data. 
2: No variables could be standardized. 
3: Could not get model data. 
4: No variables could be standardized. 

我也尝试了以下但仍然收到错误消息:

suppressWarnings(mice::mice(trial, m = 2)) %>%
  with(glm(death ~ marker + grade, family = "binomial")) %>%
  tbl_regression(tidy_fun = purrr::partial(tidy_standardize, method = "posthoc"), 
                 exponentiate = TRUE, conf.int = TRUE, conf.level = 0.95)
x There was an error calling `tidy_fun()`. Most likely, this is because the
function supplied in `tidy_fun=` was misspelled, does not exist, is not
compatible with your object, or was missing necessary arguments (e.g. `conf.level=` or `conf.int=`). See error message below.
Error: Error in .model_parameters_generic(model = mice::pool(model), ci = ci, : formal argument "standardize" matched by multiple actual arguments

与未估算的数据不同,mice 不会输出 table,因此必须在之后使用 complete 进行转换。这个怎么样:

library(tidyverse)
library(broom.mixed)
library(broom)
library(survival)
library(gtsummary)
library(mice)

data(trial)

mice(trial, m = 2) %>%
  complete() %>%
  as_tibble() %>%
  glm(death ~ marker + grade, data = ., family = "binomial") %>%
  tbl_regression(
    tidy_fun = tidy_standardize,
    exponentiate = TRUE, conf.int = TRUE, conf.level = 0.95
  )

很遗憾,收拾机无法组合或堆叠。

为了得到你想要的,我建议你在建模步骤中标准化协变量,而不是等到模型被估计出来。

示例如下!

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.0'

tbl <-
  suppressWarnings(mice::mice(trial, m = 2)) %>%
  with(glm(death ~ scale(marker) + grade, family = "binomial")) %>%
  tbl_regression(exponentiate = TRUE)
#> pool_and_tidy_mice(): Tidying mice model with
#> `mice::pool(x) %>% mice::tidy(exponentiate = TRUE, conf.int = TRUE, conf.level = 0.95)`

reprex package (v2.0.1)

创建于 2021-12-10