Skip to contents

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
1
Drug B
N = 102
1
p-value2
Grade

>0.9
    I 35 (36%) 33 (32%)
    II 32 (33%) 36 (35%)
    III 31 (32%) 33 (32%)
1 n (%)
2 Fisher’s Exact Test for Count Data with simulated p-value (based on 2000 replicates)
# \donttest{ iris |> srvyr::as_survey() |> tbl_svysummary( include = Petal.Length, by = Species ) |> add_p(test = all_continuous() ~ svyttest_oneway)
Characteristic setosa
N = 50
1
versicolor
N = 50
1
virginica
N = 50
1
p-value2
Petal.Length 1.50 (1.40, 1.60) 4.30 (4.00, 4.60) 5.50 (5.10, 5.90) <0.001
1 Median (Q1, Q3)
2 Design-based one-way analysis of means
# }