gpt4 book ai didi

r - add_p 中的错误()' for variable X and test ' fisher.test',省略了 p 值

转载 作者:行者123 更新时间:2023-12-05 08:50:44 25 4
gpt4 key购买 nike

当我尝试使用 add_p() 函数获取我的变量(具有 10 个水平)和具有两个水平的分类变量(是/否)之间差异的 p 值时,出现以下错误。我不确定如何提供可重现的示例。根据试验数据,我想我的by变量将是具有 10 个水平的“T 阶段”变量,而分类变量将是:(1)“化疗治疗”具有 2 个水平,以及 (2 ) “Chemotherapy Treatment2”有 4 个级别。但这是我运行的代码。

library(gtsummary)
library(tidyverse)
miro_def %>%
select(mheim, age_dx, time_t1d_yrs, gender, collard, fhist_pandz) %>%
tbl_summary(by = mheim, missing = "no",
type = list(c(gender, collard, fhist_pandz, mheim) ~ "categorical"),
label = list(gender ~ "Gender",
fhist_pandz ~ "Family history of PD",
age_dx ~ "Age at diagnosis",
time_t1d_yrs ~ "Follow-up(years)")) %>%
add_p() %>%
# style the output with custom header
#modify_header(stat_by = "{level}") %>%
# convert to kableExtra as_kable_extra(booktabs = TRUE) %>%
# reduce font size to make table fit. # you may also use the `latex_options = "scale_down"` argument here.
kable_styling(font_size = 7, latex_options = "scale_down")

但是,我确实通过变量(10 个水平)和其他变量(连续/数字)得到了这个 p 值

  1. 如何修复此错误?
  2. 如果我有提到的多级变量和多级(>2 级)分类变量,我应该做些什么来获得 p 值?

    变量“gender”和测试“fisher.test”的“add_p()”中存在错误,省略了 p 值:stats::fisher.test(data[[variable]], as.factor(data[[by]]) 中的错误:FEXACT 错误 7(位置)。 LDSTP=18540 对于这个问题来说太小了,(pastp=51.2364, ipn_0:=ipoin[itp=150]=215, stp[ipn_0]=40.6787)。增加工作空间或考虑使用“simulate.p.value=TRUE”变量“collard”和测试“fisher.test”的“add_p()”中存在错误,省略了 p 值:stats::fisher.test(data[[variable]], as.factor(data[[by]]) 中的错误:FEXACT 错误 7(位置)。 LDSTP=18570 对于这个问题来说太小了,(pastp=37.0199, ipn_0:=ipoin[itp=211]=823, stp[ipn_0]=23.0304)。增加工作空间或考虑使用“simulate.p.value=TRUE”变量“fhist_pandz”和测试“fisher.test”的“add_p()”中存在错误,省略了 p 值:stats::fisher.test(data[[variable]], as.factor(data[[by]]) 中的错误:FEXACT 错误 7(位置)。 LDSTP=18570 对于这个问题来说太小了,(pastp=36.4614, ipn_0:=ipoin[itp=58]=1, stp[ipn_0]=31.8106)。增加工作空间或考虑使用“simulate.p.value=TRUE”

最佳答案

由于没有人发布答案,以下是我遇到此问题时使用的内容。按照帮助文件 ?gtsummary::add_p.tbl_summary 中给出的示例,我编写了一个自定义函数,该函数使用 simulate.p.values 运行 fisher.test = TRUE 选项:

## define custom test
fisher.test.simulate.p.values <- function(data, variable, by, ...) {
result <- list()
test_results <- stats::fisher.test(data[[variable]], data[[by]], simulate.p.value = TRUE)
result$p <- test_results$p.value
result$test <- test_results$method
result
}

## add p-values to your gtsummary table, using custom test defined above
summary_table %>%
add_p(
test = list(all_categorical() ~ "fisher.test.simulate.p.values") # this applies the custom test to all categorical variables
)

您还可以通过将默认 B = 2000 参数更改为上面的 fisher.test() 来修改计算模拟 p 值的迭代次数。

当然,所有这些都假定首先使用 Fisher 检验是合适的。

关于r - add_p 中的错误()' for variable X and test ' fisher.test',省略了 p 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61360954/

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