The “wilcox.test” Function in R
Package: Base R (no specific package required)
Purpose: Performs Wilcoxon signed-rank tests and Wilcoxon rank sum tests (Mann-Whitney tests).
General Class: Statistical Testing
Required Argument(s):
x: A numeric vector of data values for the first group (or the only group in the case of a one-sample Wilcoxon signed-rank test).
Notable Optional Arguments:
y: An optional numeric vector of data values for the second group. Used in two-sample tests.
alternative: A character string specifying the alternative hypothesis. Options include "two.sided", "greater", or "less".
mu: A numeric value specifying the hypothesized median in a one-sample Wilcoxon signed-rank test.
paired: A logical value indicating whether to perform a paired Wilcoxon signed-rank test. The default is FALSE.
exact: A logical value indicating whether to compute an exact p-value for small samples. The default is FALSE.
conf.int: A logical value indicating whether to compute a confidence interval for the location parameter. The default is FALSE.
conf.level: The confidence level for the confidence interval. The default is 0.95.
Example:
# Example data for a two-sample Wilcoxon test
set.seed(123)
group1 <- rnorm(30, mean = 10, sd = 2)
group2 <- rnorm(30, mean = 12, sd = 2)
# Perform a two-sample Wilcoxon test
result <- wilcox.test(group1, group2)
# Display the result
print(result)In this example, the wilcox.test function is used to perform a two-sample Wilcoxon test (Mann-Whitney test) comparing the medians of two groups (group1 and group2). The result of the test, including the test statistic, p-value, and optionally a confidence interval, is then printed to the console.