变量 X 的 add_p()' 和测试 'fisher.test' 中出现错误,省略 p 值

Nel*_*lly 3 r gtsummary

当我尝试使用 add_p() 函数获取 by 变量(有 10 个级别)和有两个级别的分类变量(是/否)之间差异的 p 值时,出现以下错误。我不确定如何提供可重现的示例。根据试验数据,我想象我的变量将是具有 10 个级别的“T 阶段”变量,分类变量将是:(1)“化疗治疗”具有 2 个级别,(2)“化疗治疗 2”具有 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")
Run Code Online (Sandbox Code Playgroud)

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

  1. 我该如何修复这个错误?
  2. 如果我有提到的多级变量和多级(>2 级)分类变量,我是否应该做一些特殊的事情来获得 p 值?

    变量“性别”和测试“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”

use*_*603 6

由于没有人发布答案,这就是我遇到此问题时使用的内容。按照帮助文件中给出的示例?gtsummary::add_p.tbl_summary,我编写了一个使用fisher.test以下simulate.p.values = 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
) 
Run Code Online (Sandbox Code Playgroud)

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

当然,所有这些都假设首先使用费舍尔检验是合适的。