test.bm: Brunner-Munzel Test for Stochastic Equality

View source: R/test.bm.R

test.bmR Documentation

Brunner-Munzel Test for Stochastic Equality

Description

This function performs two-sample and paired-sample (Permuted) Brunner-Munzel test (Brunner & Munzel, 2000) using either a t-distribution with a Satterthwaite-Welch degrees of freedom approximation, an exact permutation test, or a randomization test (Neubert & Brunner, 2007).

Usage

test.bm(...)

## Default S3 method:
test.bm(data = NULL, ..., x = NULL, y = NULL, paired = FALSE,
        method = c("t", "logit", "perm"), alternative = c("two.sided", "less", "greater"),
        scale = c("prob", "diff", "logodds", "odds"), hypo = FALSE, descript = TRUE,
        conf.level = 0.95, nperm = 10000, seed = 42, digits = 3, p.digits = 3,
        as.na = NULL, write = NULL, append = TRUE, check = TRUE, output = TRUE)

## S3 method for class 'formula'
test.bm(formula, data, method = c("t", "logit", "perm"),
        alternative = c("two.sided", "less", "greater"),
        scale = c("prob", "diff", "logodds", "odds"), hypo = FALSE, descript = TRUE,
        conf.level = 0.95, p.adj = "none", nperm = 10000, seed = 42, na.omit = FALSE,
        digits = 3, p.digits = 3, as.na = NULL, write = NULL, append = TRUE,
        check = TRUE, output = TRUE, ...)

Arguments

data

a data frame. Note that data are specified either by using the argument data or by using the arguments x and y.

...

an expression indicating the variable names in data, e.g., test.bm(dat, x1, x2). Note that the operators +, -, ~, :, ::, and ! can also be used to select variables, see 'Details' in the df.subset function.

x

a numeric vector of data values.

y

a numeric vector of data values.

formula

in case of two sample Brunner-Munzel test (i.e., paired = FALSE), a formula of the form y ~ group where group is a numeric variable, character variable or factor with two values or factor levels giving the corresponding groups.

paired

logical: if TRUE, paired-sample Brunner-Munzel-test is computed.

method

a character string indicating the method used for statistical significance testing, i.e., "t" for a t-distribution with Satterthwaite-Welch degrees of freedom approximation, "logit" for a t-distribution with Satterthwaite-Welch degrees of freedom approximation and logit transformation for range-preserving confidence intervals, and "perm" for a studentized permutation or randomization test that is recommended for a better control of the type I error rate when sample sizes are small (smaller than 15 per group).

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less".

scale

a character string indicating the scale of the reported estimated and confidence interval, i.e., "prob" (default) for P(X < Y) + 0.5(P(X = Y) with range [0, 1] and a null value of 0.5, "diff" for P(X < Y) - P(X > Y) with range [-1, 1] and a null value of 0, "logodds" for log[P/(1 - P)] with range [-Inf, Inf] and a null value of 0, and "odds" for P/(1 - P) with range [0, Inf] and a null value of 1. Note that the statistical test always operates on the probability scale.

hypo

logical: if TRUE (default), null and alternative hypothesis are shown on the console.

descript

logical: if TRUE (default), descriptive statistics are shown on the console.

conf.level

a numeric value between 0 and 1 indicating the confidence level of the interval.

p.adj

a character string indicating an adjustment method for multiple testing based on p.adjust, i.e., none (default), bonferroni, holm, hochberg, hommel, BH, BY, or fdr. See help page of the p.adjust function.

nperm

a numeric value (default: 10000) indicating the maximum number of permutations used when method = "perm". If the number of complete permutations, i.e., choose(N, n.x) in the two-sample design and 2^n in the paired-sample design, is smaller than or equal nperm, an exact permutation test is conducted, while a randomization test based on nperm samples of unique permutations is conducted when the number of complete permutations is greater than nperm.

seed

a numeric value specifying the seed of the pseudo-random numbers used when drawing permutation samples.

na.omit

logical: if TRUE, incomplete cases are removed before conducting the analysis (i.e., listwise deletion) when specifying more than one outcome variable.

digits

an integer value indicating the number of decimal .places to be used for displaying descriptive statistics and confidence interval.

p.digits

an integer value indicating the number of decimal .places to be used for displaying the p-value.

as.na

a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis.

write

a character string naming a file for writing the output into either a text file with file extension ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

sample

type of sample, i.e., two- or paired sample

formula

formula

data

data frame with the outcome and grouping variable

args

specification of function arguments

result

result table

Note

This function is based on the brunner_munzel() and ses_calc() function in the TOSTER package by Daniel Lakens and Aaron Caldwell.

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Schüürhuis, S., Konietschke, F., & Brunner, E. (2025). A New Approach to the nonparametric Behrens-Fisher problem With compatible confidence iIntervals. Biometrical Journal, 67(6), e70096. https://doi.org/10.1002/bimj.70096

Karch, J. D. (2021). Psychologists should use Brunner-Munzel’s instead of Mann-Whitney’s U Test as the default nonparametric procedure. Advances in Methods and Practices in Psychological Science, 4(2). https://doi.org/10.1177/2515245921999

Neubert, K., & Brunner, E. (2007). A studentized permutation test for the non-parametric Behrens-Fisher problem. Computational Statistics & Data Analysis, 51(10), 5192–5204. https://doi.org/10.1016/j.csda.2006.05.024

See Also

test.t, test.welch, test.z

Examples

#————————————————————————————————————————————————————————————————————————————
# Two-Sample Design

# Example 1a: Two-sided two-sample Brunner-Munzel test
test.bm(mpg ~ vs, data = mtcars)

# Example 1b: Alternative specification without using the '...' argument
test.bm(x = df.subset(mtcars, mpg, subset = vs == 0),
        y = df.subset(mtcars, mpg, subset = vs == 1))

# Example 1c: Two-sided two-sample Brunner-Munzel randomization test
# Sample of 10000 out of choose(32, 18) = 471435600 permutations
test.bm(mpg ~ vs, data = mtcars, method = "perm")

# Example 1d: Two-sided two-sample Brunner-Munzel permutation test
# Complete permutation of choose(13, 8) = 1287 permutations
test.bm(x = c(3, 1, 4, 2, 5, 3, 6, 7), y = c(5, 2, 4, 3, 1), method = "perm")

# Example 1e: One-sided two-sample Brunner-Munzel test
test.bm(mpg ~ vs, data = mtcars, alternative = "greater")

# Example 1f: Multiple two-sample Brunner-Munzel tests
test.bm(cbind(mpg, cyl, disp, hp, drat, wt) ~ vs, data = mtcars)

# Example 1g: Multiple two-sample Brunner-Munzel tests, bonferroni correction
test.bm(cbind(mpg, cyl, disp, hp, drat, wt) ~ vs, data = mtcars, p.adj = "bonferroni")

#————————————————————————————————————————————————————————————————————————————
# Paired-Sample Design

# Example 2a: Two-sided paired-sample Brunner-Munzel test
test.bm(mtcars, drat, wt, paired = TRUE)

# Example 2b: Alternative specification without using the '...' argument
test.bm(mtcars[, c("drat", "wt")], paired = TRUE)

# Example 2c: Alternative specification without using the '...' argument
test.bm(x = mtcars$drat, y = mtcars$wt, paired = TRUE)

# Example 2d: Two-sided paired-sample Brunner-Munzel test with logit transformation
test.bm(mtcars, drat, wt, paired = TRUE, method = "logit")

## Not run: 
#————————————————————————————————————————————————————————————————————————————
# Write Results

# Example 3a: Write results into a text file
test.bm(mpg ~ vs, data = mtcars, write = "BM-Test.txt")

# Example 3b: Write results into an Excel file
test.bm(mpg ~ vs, data = mtcars, write = "BM-Test.xlsx")

## End(Not run)

misty documentation built on Nov. 24, 2026, 5:06 p.m.

Related to test.bm in misty...