[英]error in add_p()' for variable X and test 'fisher.test', p-value omitted
I get the error below when I try to use the add_p() function to get a p-value for differences between my by variable (with 10 levels) and a categorical variable with two levels (yes/no).当我尝试使用 add_p() function 来获取我的 by 变量(具有 10 个级别)和具有两个级别(是/否)的分类变量之间差异的 p 值时,出现以下错误。 I am not sure how to provide a reproducible example.
我不确定如何提供可重现的示例。 From the trials data, I imagine my by variable would be the "T Stage" variable with 10 levels, and the categorical variables would be: (1) "Chemotherapy Treatment" with 2 levels, and (2) "Chemotherapy Treatment2" with 4 levels.
根据试验数据,我想我的 by变量将是具有 10 个级别的“T 阶段”变量,分类变量将是:(1)具有 2 个级别的“化疗治疗”,以及(2)具有 4 个级别的“化疗治疗 2”水平。 But here is the code I ran.
但这是我运行的代码。
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")
However, I do get a p-value for this by variable (10 levels) with other variables (which are continous/numeric)但是,我确实通过变量(10 个级别)和其他变量(连续/数字)得到了一个 p 值
In the case where I have the mentioned multilevel by variable and a multilevel (>2 levels) categorical variable, is there something special I should do to get a p-value?在我有提到的多级变量和多级(> 2级)分类变量的情况下,我应该做一些特别的事情来获得p值吗?
There was an error in 'add_p()' for variable 'gender' and test 'fisher.test', p-value omitted: Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 7(location).变量“性别”和测试“fisher.test”的“add_p()”中存在错误,省略了 p 值:stats::fisher.test(data[[variable]], as.factor(data[ [by]])):FEXACT 错误 7(位置)。 LDSTP=18540 is too small for this problem, (pastp=51.2364, ipn_0:=ipoin[itp=150]=215, stp[ipn_0]=40.6787).
LDSTP=18540 对于这个问题来说太小了,(pastp=51.2364, ipn_0:=ipoin[itp=150]=215, stp[ipn_0]=40.6787)。 Increase workspace or consider using 'simulate.p.value=TRUE' There was an error in 'add_p()' for variable 'collard' and test 'fisher.test', p-value omitted: Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 7(location).
增加工作空间或考虑使用“simulate.p.value=TRUE”变量“collard”和测试“fisher.test”的“add_p()”中存在错误,省略了 p 值:stats::fisher.test 中的错误(data[[variable]], as.factor(data[[by]])):FEXACT 错误 7(位置)。 LDSTP=18570 is too small for this problem, (pastp=37.0199, ipn_0:=ipoin[itp=211]=823, stp[ipn_0]=23.0304).
LDSTP=18570 对于这个问题来说太小了,(pastp=37.0199, ipn_0:=ipoin[itp=211]=823, stp[ipn_0]=23.0304)。 Increase workspace or consider using 'simulate.p.value=TRUE' There was an error in 'add_p()' for variable 'fhist_pandz' and test 'fisher.test', p-value omitted: Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 7(location).
增加工作空间或考虑使用 'simulate.p.value=TRUE' 变量 'fhist_pandz' 和测试 'fisher.test' 的 'add_p()' 中有错误,省略 p 值:stats::fisher.test 中的错误(data[[variable]], as.factor(data[[by]])):FEXACT 错误 7(位置)。 LDSTP=18570 is too small for this problem, (pastp=36.4614, ipn_0:=ipoin[itp=58]=1, stp[ipn_0]=31.8106).
LDSTP=18570 对于这个问题来说太小了,(pastp=36.4614, ipn_0:=ipoin[itp=58]=1, stp[ipn_0]=31.8106)。 Increase workspace or consider using 'simulate.p.value=TRUE'
增加工作空间或考虑使用 'simulate.p.value=TRUE'
since nobody posted an answer, here's what I used when coming across this.由于没有人发布答案,这就是我遇到这个时使用的。 Following the Examples given in the help file
?gtsummary::add_p.tbl_summary
, I composed a custom function that runs fisher.test
with the simulate.p.values = TRUE
option:按照帮助文件
?gtsummary::add_p.tbl_summary
中给出的示例,我编写了一个自定义 function 运行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
)
You can also amend the number of iterations for computing the simulated p-values by changing the default B = 2000
parameter to fisher.test()
above.您还可以通过将默认
B = 2000
参数更改为上面的fisher.test()
来修改计算模拟 p 值的迭代次数。
All this assumes, of course, that it's appropriate to use Fisher's test in the first place.当然,所有这些都假设首先使用 Fisher 检验是合适的。
Since it fixed the issue for me, I would like to indicate that since version 1.3.6
of gtsummary
there is an option in add_p()
with which you can specify arguments to the test functions (ie test.args
).因为它为我解决了这个问题,所以我想指出,自从 gtsummary
1.3.6
版以来, gtsummary
add_p()
中有一个选项,您可以使用它指定 arguments 到测试函数(即test.args
)。 Thank you to the developers for this!感谢开发人员为此!
From the NEWS :来自新闻:
Each add_p()
method now has the test.args = argument
.每个
add_p()
方法现在都有test.args = argument
。 Use this argument to pass additional arguments to the statistical method, eg使用此参数将额外的 arguments 传递给统计方法,例如
add_p(test = c(age, marker) ~ "t.test",
test.args = c(age, marker) ~ list(var.equal = TRUE))
It is also explained in the add_p()
help (ie ?add_p
). add_p()
帮助(即?add_p
)中也对此进行了说明。
I had a similar problem.我有一个类似的问题。 You have to increase your workspace with
test.args
within add_p()
.您必须在
add_p()
中使用test.args
来增加您的工作空间。
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(test.args = variable_with_no_pval ~ list(workspace=2e9))
or或者
add_p(test.args = all_test("fisher.test") ~ list(workspace=2e9))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.