| f_wilcox_test | R Documentation |
Performs One-sample (Wilcoxon signed rank), Two-sample independent (Wilcoxon rank sum / Mann-Whitney U), or Paired (Wilcoxon signed rank) tests on a given dataset. Several response parameters can be analysed in sequence (formula interface). Additionally, a vector interface similar to stats::wilcox.test() is supported.
f_wilcox_test(x, ...)
## S3 method for class 'formula'
f_wilcox_test(
formula,
data = NULL,
paired = FALSE,
conf.level = NULL,
mu = 0,
alternative = "two.sided",
norm_plots = TRUE,
alpha = 0.05,
intro_text = TRUE,
close_generated_files = FALSE,
open_generated_files = TRUE,
output_type = "default",
save_as = NULL,
save_in_wdir = FALSE,
...
)
## Default S3 method:
f_wilcox_test(
x,
y = NULL,
paired = FALSE,
conf.level = NULL,
mu = 0,
alternative = "two.sided",
norm_plots = TRUE,
alpha = 0.05,
intro_text = TRUE,
close_generated_files = FALSE,
open_generated_files = TRUE,
output_type = "default",
save_as = NULL,
save_in_wdir = FALSE,
...
)
x |
Numeric vector of data values (one-sample or first group for two-sample),
or a formula of the form |
... |
For the formula method: additional arguments forwarded to
the row-filtering step. The arguments |
formula |
A formula specifying the model (alternative to using x/y).
More response variables can be added using |
data |
A data frame containing the variables when using the formula interface. |
paired |
Logical. If Note on factor level order: The formula interface computes
differences as
# Set levels at creation
group <- factor(group, levels = c("pre", "post"))
# Or relevel an existing factor
group <- relevel(group, ref = "pre")
A reversed level order flips the sign of the estimate and CI but does not affect the W statistic or p-value. |
conf.level |
Numeric. Confidence level of the interval.
Default is |
mu |
Numeric. The hypothesised value of the pseudo-median (one-sample) or location shift (paired/two-sample) under H0. Default is 0. |
alternative |
Character string. |
norm_plots |
Logical. If |
alpha |
Numeric. Significance level. Default is |
intro_text |
Logical. If |
close_generated_files |
Logical. Closes open Excel/Word files before writing.
Works on Windows (taskkill), macOS (pkill) and Linux (pkill/soffice).
Default |
open_generated_files |
Logical. Whether to open the generated output
files after creation. Defaults to |
output_type |
Character string specifying the output format. Default is
|
save_as |
Character. Specific path/filename for output. |
save_in_wdir |
Logical. Save in working directory. |
y |
Optional numeric vector (second group) for two-sample tests if using the vector interface. Ignored when a formula is supplied. |
An object of class 'f_wilcox_test', a named list with one
element per response variable. Each element contains the
stats::wilcox.test() result, the formatted console/markdown text
blocks, the diagnostic plot file path, and a publication-ready main effect
plot as a ggplot2 object (main_effect_plot). The plot shows
the estimated parameter with its confidence interval against the raw data:
the two group medians each with a distribution-free median confidence
interval (two-sample), the sample pseudo-median (Hodges-Lehmann estimate)
with a reference line at mu (one-sample), or the pseudo-median of
the per-pair differences with a reference line at mu (paired).
By default this function calls stats::wilcox.test(conf.int = TRUE),
which bases its confidence interval and hypothesis test on the
Hodges-Lehmann estimator, not the raw sample median. This is
standard behaviour of the Wilcoxon test, not something specific to this
function. This function explicitly labels the estimator for what it is,
because it is commonly mislabelled as "CI for the median" in textbooks
and software output.
The estimator works differently depending on the test type:
One-sample: The pseudo-median is the middle value of all possible pairwise averages of your data points (including each value paired with itself). For a perfectly symmetric distribution it equals the sample median; for skewed data the two can differ.
Paired: The paired differences (observation 1 minus observation 2 within each pair) are computed first, and the pseudo-median of those differences is estimated. This is conceptually a one-sample problem applied to the differences, not a comparison of two independent groups. The CI is for the pseudo-median of the differences, not for the difference between the two separate sample medians.
Two-sample independent: The location shift is the median
of all n_1 \times n_2 pairwise differences (one value from Group 1
minus one from Group 2). It answers: by how much does a randomly
chosen value from Group 1 tend to exceed a randomly chosen value from
Group 2? When both groups have the same distributional shape it equals
the raw difference in sample medians; when shapes differ, the two values can
diverge.
In all three cases the sample median(s) are reported separately for descriptive purposes only.
# Two-sample Wilcoxon rank-sum test
f_wilcox_test(mpg ~ am, data = mtcars, output_type = "console")
# Retrieve and customise the stored main effect plot (ggplot object)
result <- f_wilcox_test(mpg ~ am, data = mtcars, output_type = "default")
result[["mpg"]]$main_effect_plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.