Provides a pipe-friendly framework to performs one and two sample Wilcoxon tests.

wilcox_test(data, formula, comparisons = NULL, ref.group = NULL,
p.adjust.method = "holm", paired = FALSE, exact = NULL,
alternative = "two.sided", mu = 0, conf.level = 0.95,
detailed = FALSE)

pairwise_wilcox_test(data, formula, comparisons = NULL,
ref.group = NULL, p.adjust.method = "holm", detailed = FALSE, ...)

## Arguments

data a data.frame containing the variables in the formula. a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, formula = TP53 ~ cancer_group. A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", "C")) a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group). If ref.group = "all", pairwise two sample tests are performed for comparing each grouping variable levels against all (i.e. basemean). method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't want to adjust the p value (not recommended), use p.adjust.method = "none". a logical indicating whether you want a paired test. a logical indicating whether an exact p-value should be computed. a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter. a number specifying an optional parameter used to form the null hypothesis. confidence level of the interval. logical value. Default is FALSE. If TRUE, a detailed result is shown. other arguments to be passed to the function wilcox.test.

## Value

return a data frame with some of the following columns:

• .y.: the y variable used in the test.

• group1,group2: the compared groups in the pairwise tests.

• n,n1,n2: Sample counts.

• statistic: Test statistic used to compute the p-value.

• p: p-value.

• p.adj: the adjusted p-value.

• method: the statistical test used to compare groups.

• p.signif, p.adj.signif: the significance level of p-values and adjusted p-values, respectively.

The returned object has an attribute called args, which is a list holding the test arguments.

## Details

- pairwise_wilcox_test() applies the standard two sample Wilcoxon test to all possible pairs of groups. This method calls the wilcox.test(), so extra arguments are accepted.

- If a list of comparisons is specified, the result of the pairwise tests is filtered to keep only the comparisons of interest.The p-value is adjusted after filtering.

- For a grouped data, if pairwise test is performed, then the p-values are adjusted for each group level independently.

## Functions

• wilcox_test: Wilcoxon test

• pairwise_wilcox_test: performs pairwise two sample Wilcoxon test.

## Examples

# Load data
#:::::::::::::::::::::::::::::::::::::::
data("ToothGrowth")
df <- ToothGrowth

# One-sample test
#:::::::::::::::::::::::::::::::::::::::::
df %>% wilcox_test(len ~ 1, mu = 0)#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"

# Two-samples unpaired test
#:::::::::::::::::::::::::::::::::::::::::
df %>% wilcox_test(len ~ supp)#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
# Two-samples paired test
#:::::::::::::::::::::::::::::::::::::::::
df %>% wilcox_test (len ~ supp, paired = TRUE)#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
# Compare supp levels after grouping the data by "dose"
#::::::::::::::::::::::::::::::::::::::::
df %>%
group_by(dose) %>%
wilcox_test(data =., len ~ supp) %>%