gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:51:25 26 4
gpt4 key购买 nike

我目前正在尝试使用来自 mice 的估算数据集运行 tbl_regression 通过 logistic glm 运行。我在尝试组合自定义 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

最佳答案

遗憾的是,整理器无法组合或堆叠。

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

下面的例子!

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)`

enter image description herereprex package 创建于 2021-12-10 (v2.0.1)

关于r - gtsummary::tbl_regression 使用 pool_and_tidy_mice() 和 tidy_standardize(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70300331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com