MWTest: Mann-Whitney U Test (Wilcoxon Rank-Sum, Manual...

View source: R/MannWhitneyTest.R

MWTestR Documentation

Mann-Whitney U Test (Wilcoxon Rank-Sum, Manual Implementation)

Description

Performs the Mann-Whitney U test (Wilcoxon rank-sum) for two independent groups, using a manual implementation. Suitable when the assumptions of parametric tests (normality, homogeneity of variances) are not met.

Usage

MWTest(
  grupo1,
  grupo2,
  alpha = 0.05,
  alternative = c("two.sided", "less", "greater"),
  continuity = TRUE
)

Arguments

grupo1

Numeric vector for the first group.

grupo2

Numeric vector for the second group.

alpha

Significance level (default = 0.05).

alternative

Character string specifying the alternative hypothesis. Options are "two.sided" (default), "less", or "greater".

continuity

Logical indicating whether to apply continuity correction (default = TRUE).

Details

Advantages: - Does not assume normality. - More powerful than t-test for skewed distributions.

Disadvantages: - Only compares two groups at a time. - Sensitive to unequal variances or shapes.

This implementation allows one- or two-sided alternatives and optionally applies a continuity correction.

Value

An object of class "comparacion" and "mannwhitney", containing:

  • Resultados: A data frame with the comparison name, difference in means, p-value, and significance.

  • Promedios: A named numeric vector of group means.

  • Orden_Medias: A character vector of group names ordered from highest to lowest mean.

  • Metodo: A string describing the test and hypothesis direction.

References

Mann, H. B., & Whitney, D. R. (1947). "On a Test of Whether One of Two Random Variables is Stochastically Larger than the Other." Annals of Mathematical Statistics, 18(1), 50–60.

Examples

data(d_e, package = "Analitica")
g1 <- d_e$Sueldo_actual[d_e$labor == 1]
g2 <- d_e$Sueldo_actual[d_e$labor == 2]
resultado <- MWTest(g1, g2, alternative = "greater")
summary(resultado)


Analitica documentation built on June 14, 2025, 9:07 a.m.