Learn R Programming

bayesics (version 2.0.2)

wilcoxon_test_b: Bayesian Wilcoxon Rank Sum (aka Mann-Whitney U) and Signed Rank Analyses

Description

Bayesian Wilcoxon Rank Sum (aka Mann-Whitney U) and Signed Rank Analyses

Usage

wilcoxon_test_b(
  x,
  y,
  paired = FALSE,
  p = 0.5,
  ROPE,
  prior = "centered",
  prior_shapes,
  CI_level = 0.95,
  plot = TRUE,
  seed = 1
)

Value

(returned invisible) If signed rank analysis is implemented, a list with the following:

  • posterior_mean: Posterior mean of the proportion of differences that are positive

  • CI: Credible interval of the proportion of differences that are positive

  • Pr_less_than_p: Probability proportion of differences that are positive is less than the argument p

  • Pr_in_ROPE: Probability proportion of differences that are positive is in the ROPE

  • prob_plot: Prior and posterior plot of differences that are positive

  • posterior_parameters: Posterior beta shape parameters for the proportion of differences that are positive

  • BF_for_phi_gr_onehalf_vs_phi_less_onehalf: Bayes factor giving evidence in favor of the proportion of differences that are positive being greater than one half vs. less than one half

  • dfba_wilcoxon_object: Underlying DFBA object

If rank sum analysis is implemented, a list with the following:

  • posterior_mean: Posterior mean of \(\Omega_x\) (see details)

  • CI: Credible interval for \(\Omega_x\)

  • Pr_less_than_p: Posterior probability \(\Omega_x\) is less than the argument p

  • Pr_in_ROPE: Probability \(\Omega_x\) is in the ROPE

  • prob_plot: Prior and posterior plot of \(\Omega_x\)

  • posterior_parameters: Posterior beta shape parameters for \(\Omega_x\)

  • BF_for_Omegax_gr_onehalf_vs_Omegax_less_onehalf: Bayes factor in favor of \(\Omega_x\) being greater than one half vs. less than one half

  • dfba_wilcoxon_object: Underlying DFBA object

Arguments

x

numeric vector of data values. Non-finite (e.g., infinite or missing) values will be omitted.

y

an optional numeric vector of data values: as with x non-finite values will be omitted.

paired

if TRUE and y is supplied, x-y will be the input of the Bayesian Wilcoxon signed rank test.

p

numeric.

  • Signed rank: wilcox_test_b will return the posterior probability that the population proportion of positive values (i.e., \(x>y\)) is greater than this value.

  • Rank sum/Mann-Whitney U: wilcox_test_b will return the posterior probability that the \(\Omega_x\) (see details) is greater than this value.

ROPE

If a single number, ROPE will be p\(\pm\)ROPE. If a vector of length 2, these will serve as the ROPE bounds. Defaults to \(\pm 0.05\).

prior

Prior used on the probability that x > y. Either "uniform" (Beta(1,1)), or "centered" (Beta(2,2)). This is ignored if prior_shapes is provided.

prior_shapes

Vector of length two, giving the shape parameters for the beta distribution that will act as the prior on the population proportions.

CI_level

The posterior probability to be contained in the credible interval.

plot

logical. Should a plot be shown?

seed

Always set your seed! (Unused for \(\geq\) 20 observations.)

Details

Bayesian Wilcoxon signed rank analysis For a single input vector or paired data, the Bayesian signed rank analysis will be performed. The estimand is the proportion of (differenced) values that are positive. For more information, see dfba_wilcoxon and vignette("dfba_wilcoxon",package = "DFBA").

Bayesian Wilcoxon rank sum/Mann-Whitney analysis For unpaired x and y inputs, the Bayesian rank sum analysis will be performed. The estimand is \(\Omega_x:=\lim_{n\to\infty} \frac{U_x}{U_x + U_y}\), where \(U_x\) is the number of pairs \((i,j)\) such that \(x_i > y_j\), and vice versa for \(U_y\). That is, it is the population proportion of all untied pairs for which \(x > y\). Larger values imply that \(x\) is stochastically larger than \(y\). For more information, see dfba_mann_whitney and vignette("dfba_mann_whitney",package = "DFBA").

References

Chechile, R.A. (2020). Bayesian Statistics for Experimental Scientists: A General Introduction to Distribution-Free Methods. Cambridge: MIT Press.

Chechile, R. A. (2018) A Bayesian analysis for the Wilcoxon signed-rank statistic. Communications in Statistics - Theory and Methods, https://doi.org/10.1080/03610926.2017.1388402

Chechile, R.A. (2020). A Bayesian analysis for the Mann-Whitney statistic. Communications in Statistics – Theory and Methods 49(3): 670-696. https://doi.org/10.1080/03610926.2018.1549247.

Barch DH, Chechile RA (2023). DFBA: Distribution-Free Bayesian Analysis. doi:10.32614/CRAN.package.DFBA

Examples

Run this code
# \donttest{
# Signed rank analysis
## Generate data
N = 150
set.seed(2025)
test_data = 
  data.frame(x = rbeta(N,2,10),
             y = rbeta(N,5,10))

## input differenced data
wilcoxon_test_b(test_data$x - test_data$y)
## input paired data vectors individually
wilcoxon_test_b(test_data$x,
                test_data$y,
                paired = TRUE)

## Use different priors
wilcoxon_test_b(test_data$x - test_data$y,
                prior = "uniform")
wilcoxon_test_b(test_data$x - test_data$y,
                prior_shapes = c(5,5))

## Change ROPE bounds
wilcoxon_test_b(test_data$x - test_data$y,
                ROPE = 0.1)

# Rank sum analysis
## Generate data
set.seed(2025)
N = 150
x = rbeta(N,2,10)
y = rbeta(N + 1,5,10)

## Perform analysis
wilcoxon_test_b(x,y)
# }


Run the code above in your browser using DataLab