| Type: | Package |
| Title: | (Permuted) Brunner-Munzel Test |
| Version: | 2.0 |
| Date: | 2022-8-7 |
| License: | GPL-2 | GPL-3 |
| Description: | Provides the functions for Brunner-Munzel test and permuted Brunner-Munzel test, which enable to use formula, matrix, and table as argument. These functions are based on Brunner and Munzel (2000) <doi:10.1002/(SICI)1521-4036(200001)42:1%3C17::AID-BIMJ17%3E3.0.CO;2-U> and Neubert and Brunner (2007) <doi:10.1016/j.csda.2006.05.024>, and are written with FORTRAN. |
| URL: | https://github.com/toshi-ara/brunnermunzel |
| BugReports: | https://github.com/toshi-ara/brunnermunzel/issues/ |
| RoxygenNote: | 7.2.1 |
| Suggests: | testthat, knitr, rmarkdown, dplyr, ggplot2 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | yes |
| Packaged: | 2022-08-07 10:59:11 UTC; ara |
| Author: | Toshiaki Ara [aut, cre] |
| Maintainer: | Toshiaki Ara <toshiaki.ara@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2022-08-07 15:40:11 UTC |
permuted Brunner-Munzel test
Description
This function performs the permuted Brunner-Munzel test.
Usage
brunnermunzel.permutation.test(x, ...)
## Default S3 method:
brunnermunzel.permutation.test(
x,
y,
alternative = c("two.sided", "greater", "less"),
force = FALSE,
est = c("original", "difference"),
...
)
## S3 method for class 'formula'
brunnermunzel.permutation.test(formula, data, subset = NULL, na.action, ...)
## S3 method for class 'matrix'
brunnermunzel.permutation.test(x, ...)
## S3 method for class 'table'
brunnermunzel.permutation.test(x, ...)
Arguments
x |
the numeric vector of data values from the sample 1, or 2 x n matrix of table (number of row must be 2 and column is ordinal variables). |
... |
further arguments to be passed to or from methods (This argument is for only formula). |
y |
the numeric vector of data values from the sample 2. If x is matrix or table, y must be missing. |
alternative |
a character string specifying the alternative
hypothesis, must be one of |
force |
|
est |
a method to calculate estimate and confidence interval,
must be either
This change is proposed by Dr. Julian D. Karch. |
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function which indicates what should happen when
the data contain |
Value
A list containing the following components:
method |
the characters “permuted Brunner-Munzel Test” |
data.name |
a character string giving the name of the data. |
p.value |
the |
estimate |
an estimate of the effect size |
Note
FORTRAN subroutine 'combination' in combination.f is derived from the program by shikino (http://slpr.sakura.ne.jp/qp/combination) (CC-BY-4.0). Thanks to shikono for your useful subroutine.
References
Karin Neubert and Edgar Brunner, “A studentized permutation test for the non-parametric Behrens-Fisher problem”, Computational Statistics and Data Analysis, Vol. 51, pp. 5192-5204 (2007).
See Also
This function is made in reference to following cite (in Japanese): Prof. Haruhiko Okumura (https://oku.edu.mie-u.ac.jp/~okumura/stat/brunner-munzel.html).
Examples
## 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)
brunnermunzel.permutation.test(x, y)
##
## permuted Brunner-Munzel Test
##
## data: x and y
## p-value = 0.158
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.2839506
## 'est' option
## if 'est = "difference"' return P(X<Y) - P(X>Y)
brunnermunzel.permutation.test(x, y, est = "difference")
##
## permuted Brunner-Munzel Test
##
## data: x and y
## p-value = 0.158
## sample estimates:
## P(X<Y)-P(X>Y)
## -0.4320988
## Formula interface.
dat <- data.frame(
value = c(x, y),
group = factor(rep(c("x", "y"), c(length(x), length(y))),
levels = c("x", "y"))
)
brunnermunzel.permutation.test(value ~ group, data = dat)
##
## permuted Brunner-Munzel Test
##
## data: value by group
## p-value = 0.158
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.2839506
## Pain score on the third day after surgery for 14 patients under
## the treatment Y and 11 patients under the treatment N
## (see Brunner and Munzel, 2000; Neubert and Brunner, 2007).
Y <- c(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1)
N <- c(3, 3, 4, 3, 1, 2, 3, 1, 1, 5, 4)
brunnermunzel.permutation.test(Y, N)
##
## permuted Brunner-Munzel Test
##
## data: Y and N
## p-value = 0.008038
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.788961
## Formula interface.
dat <- data.frame(
value = c(Y, N),
group = factor(rep(c("Y", "N"), c(length(Y), length(N))),
levels = c("Y", "N"))
)
brunnermunzel.permutation.test(value ~ group, data = dat)
##
## permuted Brunner-Munzel Test
##
## data: value by group
## p-value = 0.008038
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.788961
## Matrix or Table interface.
##
dat1 <- matrix(c(4, 4, 2, 1, 5, 4), nr = 2, byrow = TRUE)
dat2 <- as.table(dat1)
brunnermunzel.permutation.test(dat1) # matrix
##
## permuted Brunner-Munzel Test
##
## data: Group1 and Group2
## p-value = 0.1593
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.68
brunnermunzel.permutation.test(dat2) # table
##
## Brunner-Munzel Test
##
## permuted Brunner-Munzel Test
##
## data: A and B
## p-value = 0.1593
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.68
brunnermunzel.test
Description
This function performs the Brunner–Munzel test for stochastic
equality of two samples, which is also known as the Generalized Wilcoxon
Test. NAs from the data are omitted.
This function enables to use formula as argument.
Usage
brunnermunzel.test(x, ...)
## Default S3 method:
brunnermunzel.test(
x,
y,
alternative = c("two.sided", "greater", "less"),
alpha = 0.05,
perm = FALSE,
est = c("original", "difference"),
...
)
## S3 method for class 'formula'
brunnermunzel.test(formula, data, subset = NULL, na.action, ...)
## S3 method for class 'matrix'
brunnermunzel.test(x, ...)
## S3 method for class 'table'
brunnermunzel.test(x, ...)
Arguments
x |
the numeric vector of data values from the sample 1, or 2 x n matrix of table (number of row must be 2 and column is ordinal variables). |
... |
further arguments to be passed to or from methods (This argument is for only formula). |
y |
the numeric vector of data values from the sample 2. If x is matrix or table, y must be missing. |
alternative |
a character string specifying the alternative
hypothesis, must be one of |
alpha |
significance level, default is 0.05 for 95% confidence interval. |
perm |
logical
|
est |
a method to calculate estimate and confidence interval,
must be either
This change is proposed by Dr. Julian D. Karch. |
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function which indicates what should happen when
the data contain |
Value
A list containing the following components:
data.name |
a character string giving the name of the data. |
statistic |
the Brunner–Munzel test statistic. |
parameter |
the degrees of freedom. |
p.value |
the |
conf.int |
the confidence interval. |
estimate |
an estimate of the effect size |
Note
There exist discrepancies with Brunner and Munzel (2000) because there is a typo in the paper. The corrected version is in Neubert and Brunner (2007) (e.g., compare the estimates for the case study on pain scores). The current R function follows Neubert and Brunner (2007).
See Also
The R script of brunnermunzel.test.default is
derived from that of brunner.munzel.test
in lawstat package,
and is rewritten with FORTRAN.
Thanks to authors of lawstat package.
Examples
## 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)
brunnermunzel.test(x, y)
##
## Brunner-Munzel Test
##
## data: x and y
## Brunner-Munzel Test Statistic = -1.4673, df = 15.147, p-value = 0.1628
## 95 percent confidence interval:
## -0.02962941 0.59753064
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.2839506
## 'est' option
## if 'est = "difference"' return P(X<Y) - P(X>Y)
brunnermunzel.test(x, y, est = "difference")
##
## Brunner-Munzel Test
##
## data: x and y
## Brunner-Munzel Test Statistic = -1.4673, df = 15.147, p-value = 0.1628
## 95 percent confidence interval:
## -1.0592588 0.1950613
## sample estimates:
## P(X<Y)-P(X>Y)
## -0.4320988
## Formula interface.
dat <- data.frame(
value = c(x, y),
group = factor(rep(c("x", "y"), c(length(x), length(y))),
levels = c("x", "y"))
)
brunnermunzel.test(value ~ group, data = dat)
##
## Brunner-Munzel Test
##
## data: value by group
## Brunner-Munzel Test Statistic = -1.4673, df = 15.147, p-value = 0.1628
## 95 percent confidence interval:
## -0.02962941 0.59753064
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.2839506
## Pain score on the third day after surgery for 14 patients under
## the treatment Y and 11 patients under the treatment N
## (see Brunner and Munzel, 2000; Neubert and Brunner, 2007).
Y <- c(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1)
N <- c(3, 3, 4, 3, 1, 2, 3, 1, 1, 5, 4)
brunnermunzel.test(Y, N)
##
## Brunner-Munzel Test
##
## data: Y and N
## Brunner-Munzel Test Statistic = 3.1375, df = 17.683, p-value = 0.005786
## 95 percent confidence interval:
## 0.5952169 0.9827052
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.788961
## Formula interface.
dat <- data.frame(
value = c(Y, N),
group = factor(rep(c("Y", "N"), c(length(Y), length(N))),
levels = c("Y", "N"))
)
brunnermunzel.test(value ~ group, data = dat)
##
## Brunner-Munzel Test
##
## data: value by group
## Brunner-Munzel Test Statistic = 3.1375, df = 17.683, p-value =
## 0.005786
## 95 percent confidence interval:
## 0.5952169 0.9827052
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.788961
## Matrix or Table interface.
##
dat1 <- matrix(c(4, 4, 2, 1, 5, 4), nr = 2, byrow = TRUE)
dat2 <- as.table(dat1)
brunnermunzel.test(dat1) # matrix
##
## Brunner-Munzel Test
##
## data: Group1 and Group2
## Brunner-Munzel Test Statistic = 1.5511, df = 16.961, p-value =
## 0.1393
## 95 percent confidence interval:
## 0.4351213 0.9248787
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.68
brunnermunzel.test(dat2) # table
##
## Brunner-Munzel Test
##
## data: A and B
## Brunner-Munzel Test Statistic = 1.5511, df = 16.961, p-value =
## 0.1393
## 95 percent confidence interval:
## 0.4351213 0.9248787
## sample estimates:
## P(X<Y)+.5*P(X=Y)
## 0.68