Skip to Content

BWS_TEST

Overview

The BWS_TEST function performs the Baumgartner-Weiss-Schindler (BWS) test to compare two independent samples. The BWS test is a nonparametric statistical test that evaluates whether two samples come from the same distribution, with particular sensitivity to differences in the tails of the distributions. Unlike parametric tests such as the t-test, the BWS test does not assume normality or equal variances, making it suitable for a wider range of data types. The test statistic is calculated as:

BWS=1nx+nyi=1nx+ny[Fx(Ri)Fy(Ri)]2BWS = \frac{1}{n_x + n_y} \sum_{i=1}^{n_x + n_y} \left[ F_x(R_i) - F_y(R_i) \right]^2

where FxF_x and FyF_y are the empirical distribution functions of samples xx and yy, and RiR_i are the ranks of the combined samples. For more details, see the scipy.stats.bws_test documentation.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=BWS_TEST(x, y, [alternative])
  • x (2D list, required): First sample. Must be a 2D array (column vector) with at least two rows, containing numeric values.
  • y (2D list, required): Second sample. Must be a 2D array (column vector) with at least two rows, containing numeric values.
  • alternative (string, optional, default=‘two-sided’): Defines the alternative hypothesis. Must be one of two-sided, less, or greater.

The function returns a single-row 2D array: [statistic, pvalue], where statistic is the BWS test statistic and pvalue is the p-value for the test. If the input is invalid, an error message (string) is returned instead.

Examples

Example 1: Basic Case

Inputs:

xy
1.22.1
2.32.9
3.13.7
4.04.5

Excel formula:

=BWS_TEST({1.2;2.3;3.1;4.0}, {2.1;2.9;3.7;4.5})

Expected output:

statisticpvalue
0.3261.000

Example 2: With alternative = “less”

Inputs:

xyalternative
1.22.1less
2.32.9
3.13.7
4.04.5

Excel formula:

=BWS_TEST({1.2;2.3;3.1;4.0}, {2.1;2.9;3.7;4.5}, "less")

Expected output:

statisticpvalue
-0.3260.357

Example 3: With alternative = “greater”

Inputs:

xyalternative
1.22.1greater
2.32.9
3.13.7
4.04.5

Excel formula:

=BWS_TEST({1.2;2.3;3.1;4.0}, {2.1;2.9;3.7;4.5}, "greater")

Expected output:

statisticpvalue
-0.3260.657

Example 4: Different Samples

Inputs:

xy
10.02.0
12.03.0
13.04.0
15.05.0

Excel formula:

=BWS_TEST({10.0;12.0;13.0;15.0}, {2.0;3.0;4.0;5.0})

Expected output:

statisticpvalue
3.7110.029

Python Code

from scipy.stats import bws_test as scipy_bws_test from typing import List, Union def bws_test(x: List[List[float]], y: List[List[float]], alternative: str = 'two-sided') -> Union[List[List[float]], str]: """ Performs the Baumgartner-Weiss-Schindler test on two independent samples. Args: x: 2D list of float values. First sample. y: 2D list of float values. Second sample. alternative: Defines the alternative hypothesis ('two-sided', 'less', 'greater'). Default is 'two-sided'. Returns: 2D list with a single row: [statistic, pvalue], or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate x and y if not (isinstance(x, list) and all(isinstance(row, list) for row in x)) or len(x) < 2: return "Invalid input: x must be a 2D list with at least two rows." if not (isinstance(y, list) and all(isinstance(row, list) for row in y)) or len(y) < 2: return "Invalid input: y must be a 2D list with at least two rows." try: x_flat = [float(item) for row in x for item in row] y_flat = [float(item) for row in y for item in row] except Exception: return "Invalid input: x and y must contain only numeric values." if alternative not in ['two-sided', 'less', 'greater']: return "Invalid input: alternative must be 'two-sided', 'less', or 'greater'." try: result = scipy_bws_test(x_flat, y_flat, alternative=alternative) except Exception as e: return f"scipy.stats.bws_test error: {e}" stat, pvalue = result.statistic, result.pvalue # Convert to native float if needed try: stat = float(stat) pvalue = float(pvalue) except Exception: return "Invalid output: statistic or pvalue could not be converted to float." # Disallow nan/inf if any([isinstance(val, float) and (val != val or val in [float('inf'), float('-inf')]) for val in [stat, pvalue]]): return "Invalid output: statistic or pvalue is nan or inf." return [[stat, pvalue]]

Example Workbook

Link to Workbook

Last updated on