See gtsummary::tests for more details on how defining custom tests.
fisher.simulate.p() implements Fisher test with computation of p-values by
Monte Carlo simulation in larger than 2×2 tables (see
stats::fisher.test()).
svyttest_oneway() is designed to compare means between sub-groups for
survey objects. It is based on survey::svyttest() for comparing 2 means,
and on svyoneway() for comparing 3 means or more.
Usage
fisher.simulate.p(data, variable, by, ...)
svyttest_oneway(data, variable, by, ...)
Arguments
- data
A data set.
- variable
Name of the variable to test.
- by
Name of the by variable.
- ...
Unused.
Examples
library(gtsummary)
trial |>
tbl_summary(include = grade, by = trt) |>
add_p(test = all_categorical() ~ "fisher.simulate.p")
| Characteristic |
Drug A
N = 98 |
Drug B
N = 102 |
p-value |
|---|
| Grade |
|
|
>0.9 |
| I |
35 (36%) |
33 (32%) |
|
| II |
32 (33%) |
36 (35%) |
|
| III |
31 (32%) |
33 (32%) |
|
# \donttest{
iris |>
srvyr::as_survey() |>
tbl_svysummary(
include = Petal.Length,
by = Species
) |>
add_p(test = all_continuous() ~ svyttest_oneway)
| Characteristic |
setosa
N = 50 |
versicolor
N = 50 |
virginica
N = 50 |
p-value |
|---|
| Petal.Length |
1.50 (1.40, 1.60) |
4.30 (4.00, 4.60) |
5.50 (5.10, 5.90) |
<0.001 |
# }