bayes.wilcox.test: Bayesian First Aid Alternative to the Wilcoxon Rank Test

Description Usage Arguments Details Value References Examples

Description

Implements a Bayesian alternative to the wilcox.test function. Written as an addition to and based on the Bayesian First Aid package by Rasmus Bååth (2014). The method follows Gelman et al. (2014), and fits a normal model using JAGS after an inverse-normal rank-transformation.

Usage

1
2
3
4
5
6
bayes.wilcox.test(x, ...)

## Default S3 method:
bayes.wilcox.test(x, y, cred.mass = 0.95, mu = 0,
  paired = FALSE, n.iter = 30000, alternative = NULL, exact = NULL,
  correct = NULL, conf.int = NULL, conf.level, progress.bar = "text", ...)

Arguments

x

numeric vector of data values

...

further arguments to be passed to or from methods.

y

numeric vector of data values to be compared to x. Unlike for the wilcox.test function, this argument is required.

cred.mass

the amount of probability mass that will be contained in reported credible intervals. This argument fills a similar role as conf.level in wilcox.test

mu

number specifying an optional paramter to form the null hypothesis. See 'Details'.

paired

a logical indicating whether you want a paired test.

n.iter

The number of iterations to run the MCMC sampling.

alternative

ignored, only retained in order to maintain compability with wilcox.test

exact

ignored, only retained in order to maintain compability with wilcox.test

correct

ignored, only retained in order to maintain compability with wilcox.test

conf.int

ignored, only retained in order to maintain compability with wilcox.test

conf.level

identical to cred.mass, ignored, only retained in order to maintain compability with wilcox.test

progress.bar

The type of progress bar. Possible values are "text", "gui", and "none".

Details

The test performs an inverse-normal rank transformation on the data before the test models are run. This transformation is based on Gelman et al. (2014) and transforms the ranks of the data to quantiles of a standard Gaussian. See the package vignette for more details.

If paired = FALSE, an independent (two) sample Wilcoxon test is performed. For the two-sample wilcox test, the posterior distribution is obtained from the following model:

If paired = TRUE, a paired sample test is run, with the following model structure:

If mu is given, the hypothesis that the inverse-normal rank transformed data are larger/smaller than mu is tested.

Value

A list of class bayes_wilcox_test. It can be further inspected using the functions print, summary, plot, diagnostics.bayes_paired_wilcox_test and model.code.bayes_paired_wilcox_test, or diagnostics.bayes_two_sample_wilcox_test and model.code.bayes_two_sample_wilcox_test, respectively.

References

Rasmus Bååth (2014), “Bayesian First Aid: A Package That Implements Bayesian Alternatives to the Classical *.Test Functions in R.” In UseR! 2014 - the International R User Conference.

Andrew Gelman, John B Carlin, Hal S Stern, David B Dunson, Aki Vehtari and Donald B Rubin (2014), Bayesian Data Analysis. 3rd ed. CRC press Boca Raton, FL. Page 97.

Myles Hollander and Douglas A. Wolfe (1973), Nonparametric Statistical Methods. New York: John Wiley & Sons. Pages 27–33 (one-sample), 68–75 (two-sample). Or second edition (1999).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Using examples copied from the wilcox.test help file:

# One-sample (Paired sample) test.
# Hollander & Wolfe (1973), 29f.
# Hamilton depression scale factor measurements in 9 patients with
# mixed anxiety and depression, taken at the first (x) and second
# (y) visit after initiation of a therapy (administration of a
# tranquilizer).
x <- c(1.83,  0.50,  1.62,  2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)
# Performing a paired-sample Bayesian Wilcox test. The function can be used
# in exactly the same way as wilcox.test:
pairedBayesWilcox <- bayes.wilcox.test(x, y, paired = TRUE,
      alternative = "greater")
# Note that the argument "alternative" is ignored by bayes.wilcox.test
# Test summary
summary(pairedBayesWilcox)
# Visual Inspection
plot(pairedBayesWilcox)
# Diagnostics for MCMC
diagnostics.bayes_paired_wilcox_test(pairedBayesWilcox)
# Print out the model code, which can be modified
model.code.bayes_paired_wilcox_test(pairedBayesWilcox)
# Classical Wilcox Test for comparison
wilcox.test(x, y, paired = TRUE, alternative = "greater")


# Two-sample (independent) test.
# Hollander & Wolfe (1973), 69f.
# Permeability constants of the human chorioamnion (a placental
# membrane) at term (x) and between 12 to 26 weeks gestational
# age (y).  The alternative of interest is greater permeability
# of the human chorioamnion for the term pregnancy.
x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46)
y <- c(1.15, 0.88, 0.90, 0.74, 1.21)
indBayesWilcox <- bayes.wilcox.test(x, y, alternative = "greater")
                              # Note that the argument "alternative" is
                              # ignored by bayes.wilcox.test
# Test summary
summary(indBayesWilcox)
# Visual Inspection
plot(indBayesWilcox)
# Diagnostics for MCMC
diagnostics.bayes_two_sample_wilcox_test(indBayesWilcox)
# Print out the model code, which can be modified
model.code.bayes_two_sample_wilcox_test(indBayesWilcox)
# Classical Wilcox Test for comparison
wilcox.test(x, y, alternative = "greater")

joereinhardt/BayesianFirstAid-Wilcoxon documentation built on May 10, 2019, 10:02 a.m.