英文:
How to use car::Anova in tbl_uvregression?
问题
我正在尝试使用类似以下代码的 gee 包:
example <- trial%>%
na.omit()%>%
tbl_uvregression(
method = geepack::geeglm,
y = death,
method.args = list(
family = binomial,
id = grade,
corstr = "independence"),
exponentiate = TRUE,
add_estimate_to_reference_rows = T,
conf.level = 0.95)
这个代码很好地工作,并为所有 X 变量提供了所需的单变量分析。然而,当我尝试使用 add_global_p
时,我遇到了以下错误:运行 car::Anova()
时出错,错误消息为 "trt",可能是因为不支持这种模型类型。结果显示基于 add_global_p(anova_fun = gtsummary::tidy_wald_test)
。这也发生在所有 X 变量上。但是,我确信 car::Anova
支持这个模型类型,因为我在 geeglm 上使用过它(请参见下面的示例1):
example1 <- trial%>%na.omit()
example1.outcome <- geepack::geeglm(death ~ trt,family = binomial,id = grade,corstr = "independence", data = example1)
car::Anova(example1.outcome, type = 3, test.statistic = "Wald")
结果:
Deviance 分析表(Type III 检验)
响应变量:death
变量 | 自由度 | 卡方值 | P值 |
---|---|---|---|
intercept | 1 | 0.28 | 0.6 |
trt | 1 | 2.03 | 0.15 |
回到示例,我尝试了一些不同的方法,比如:
example%>%
add_global_p(car::Anova(type = 3, test.statistic = "Chisq"))
但它会出现以下错误:Error in car::Anova(type = 3, test.statistic = "Chisq") :
argument "mod" is missing, with no default.
我还尝试了:
add_global_p(car::Anova(example, type = 3, test.statistic = "Chisq"))
但会出现以下错误:Error in UseMethod("vcov") :
no applicable method for 'vcov' applied to an object of class "c('tbl_uvregression', 'gtsummary')"
我还尝试了:
example%>%
add_global_p(anova_fun= car::Anova)
但它说参数 mod 缺失。我尝试了一些不同的方法,但似乎无法成功。我还查看了以下问题,但仍然无法解决:https://stackoverflow.com/questions/75301035/problem-using-anova-fun-argument-in-add-global-p
额外问题:我还想知道是否可能在 p 值旁边的列中添加 Chi-squared 测试的值(示例1输出的第三列)。
英文:
I am trying to use a gee like the following code:
example <- trial%>%
na.omit()%>%
tbl_uvregression(
method = geepack::geeglm,
y = death,
method.args = list(
family = binomial,
id = grade,
corstr = "independence"),
exponentiate = TRUE,
add_estimate_to_reference_rows = T,
conf.level = 0.95)
Which works just fine and gives me desired univariate analysis for all Xs. However, when I try to use add_global_p, I get the following error: There was an error running car::Anova()
for "trt", likely due to this model type not being supported. The results displayed are based on add_global_p(anova_fun = gtsummary::tidy_wald_test)
. This also happens to all Xs. However, I know for sure this model is supported by car::Anova since I used it with geeglm (see example 1 down):
example1 <- trial%>%na.omit()
example1.outcome <- geepack::geeglm(death ~ trt,family = binomial,id = grade,corstr = "independence", data = example1)
car::Anova(example1.outcome, type = 3, test.statistic = "Wald")
Outcome:
Analysis of Deviance table (Type III tests)
Response: death
variable | Df | Chisq | Pr(>chisq) |
---|---|---|---|
intercept | 1 | 0.28 | 0.6 |
trt | 1 | 2.03 | 0.15 |
Going back to example, I tried a few different things such as:
example%>%
add_global_p(car::Anova(type = 3, test.statistic = "Chisq"))
But it gives the following error: Error in car::Anova(type = 3, test.statistic = "Chisq") :
argument "mod" is missing, with no default.
I also tried:
add_global_p(car::Anova(example, type = 3, test.statistic = "Chisq"))
but the following error arises: Error in UseMethod("vcov") :
no applicable method for 'vcov' applied to an object of class "c('tbl_uvregression', 'gtsummary')"
I also tried:
example%>%
add_global_p(anova_fun= car::Anova)
But it says argument mod is missing. I tried a few different things, but I do not seem to be able to get it. I also looked at the following question, and still could not figure it out: https://stackoverflow.com/questions/75301035/problem-using-anova-fun-argument-in-add-global-p
Bonus: I am also wondering if it would be possible to add the values of Chisq test (the 3rd column in the output of example 1) in a column next to p-values.
答案1
得分: 0
请参阅下面的示例:
library(gtsummary)
tbl <-
trial %>%
na.omit()%>%
tbl_uvregression(
method = geepack::geeglm,
y = death,
include = response,
method.args = list(
family = binomial,
id = grade,
corstr = "independence"),
exponentiate = TRUE,
add_estimate_to_reference_rows = T,
conf.level = 0.95
)
# 这是 geepack::geeglm() 模型
class(tbl$tbls$response$model_obj)
#> [1] "geeglm" "gee" "glm" "lm"
# 与 'car::Anova()' 不兼容
car::Anova(tbl$tbls$response$model_obj)
#> Error in glm.control(trace = 0L, jack = 0L, j1s = 0L, fij = 0L, maxit = 25L, : unused arguments (jack = 0, j1s = 0, fij = 0)
# 如错误消息所示,使用 tidy_wald_test() 函数解决错误
# FYI,此函数是为 geepack 模型编写的
tbl %>%
add_global_p(anova_fun = gtsummary::tidy_wald_test) %>%
as_kable() # 转换为 kable 以便在 StackOverflow 上显示
特征 | N | OR | 95% CI | p-value |
---|---|---|---|---|
肿瘤反应 | 173 | 0.35 | 0.19, 0.66 | <0.001 |
<sup>创建于 2023-06-29,使用 reprex v2.0.2</sup>
英文:
See below for a working example:
library(gtsummary)
tbl <-
trial %>%
na.omit()%>%
tbl_uvregression(
method = geepack::geeglm,
y = death,
include = response,
method.args = list(
family = binomial,
id = grade,
corstr = "independence"),
exponentiate = TRUE,
add_estimate_to_reference_rows = T,
conf.level = 0.95
)
# this is the geepack::geeglm() model
class(tbl$tbls$response$model_obj)
#> [1] "geeglm" "gee" "glm" "lm"
# not compatible with `car::Anova()`
car::Anova(tbl$tbls$response$model_obj)
#> Error in glm.control(trace = 0L, jack = 0L, j1s = 0L, fij = 0L, maxit = 25L, : unused arguments (jack = 0, j1s = 0, fij = 0)
# the non-compatibility is shown below from within gtsummary
tbl_error <- tbl %>% add_global_p()
#> ✖ There was an error running `car::Anova()` for "response", likely due to this model type not being supported. The results displayed are based on `add_global_p(anova_fun = gtsummary::tidy_wald_test)`
# as the error message indicates, use the tidy_wald_test() function to get around the error
# FYI, this function was written FOR geepack models
tbl %>%
add_global_p(anova_fun = gtsummary::tidy_wald_test) %>%
as_kable() # convert to kable so it will display on StackOverflow
Characteristic | N | OR | 95% CI | p-value |
---|---|---|---|---|
Tumor Response | 173 | 0.35 | 0.19, 0.66 | <0.001 |
<sup>Created on 2023-06-29 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论