ALEXANDERGOVERN
Overview
The ALEXANDERGOVERN
function performs the Alexander-Govern test for equality of means across multiple independent groups, allowing for heterogeneity of variance. This robust alternative to one-way ANOVA is useful when the assumption of equal variances is violated. The test statistic is computed as described in the SciPy documentation :
where is the weight for group , is the mean of group , is the overall mean, is the variance of group , and is the sample size of group .
This wrapper exposes only the most commonly used parameter: a 2D array of samples, where each column is a group and each row is an observation. Parameters such as nan_policy
, axis
, and keepdims
are omitted for Excel compatibility. This example function is provided as-is without any representation of accuracy.
Usage
To use the function in Excel:
=ALEXANDERGOVERN(samples)
samples
(2D list, required): Table of numeric values. Each column represents a group/sample; each row an observation. Must have at least two columns and two rows.
The function returns a single-row 2D array: [statistic, pvalue]
(both floats), or an error message (string) if the input is invalid. The statistic quantifies the difference in means across groups, and the p-value indicates the probability of observing such a difference under the null hypothesis of equal means.
Examples
Example 1: Two Groups, Basic
Inputs:
samples | |
---|---|
1.2 | 2.3 |
1.5 | 2.1 |
1.3 | 2.2 |
1.4 | 2.4 |
Excel formula:
=ALEXANDERGOVERN({1.2,2.3;1.5,2.1;1.3,2.2;1.4,2.4})
Expected output:
statistic | pvalue |
---|---|
15.074 | 0.000 |
Example 2: Three Groups
Inputs:
samples | ||
---|---|---|
1.2 | 2.3 | 3.1 |
1.5 | 2.1 | 3.2 |
1.3 | 2.2 | 3.0 |
1.4 | 2.4 | 3.3 |
Excel formula:
=ALEXANDERGOVERN({1.2,2.3,3.1;1.5,2.1,3.2;1.3,2.2,3.0;1.4,2.4,3.3})
Expected output:
statistic | pvalue |
---|---|
22.510 | 0.000 |
Example 3: Groups with Close Means
Inputs:
samples | |
---|---|
10.0 | 10.1 |
10.2 | 10.0 |
10.1 | 10.2 |
10.0 | 10.1 |
Excel formula:
=ALEXANDERGOVERN({10.0,10.1;10.2,10.0;10.1,10.2;10.0,10.1})
Expected output:
statistic | pvalue |
---|---|
0.132 | 0.716 |
Example 4: Groups with Different Variance
Inputs:
samples | |
---|---|
1.0 | 10.0 |
1.1 | 10.1 |
0.9 | 9.9 |
1.2 | 10.2 |
Excel formula:
=ALEXANDERGOVERN({1.0,10.0;1.1,10.1;0.9,9.9;1.2,10.2})
Expected output:
statistic | pvalue |
---|---|
40.811 | 0.000 |
Python Code
from scipy.stats import alexandergovern as scipy_alexandergovern
from typing import List, Union
def alexandergovern(samples: List[List[float]]) -> Union[List[List[float]], str]:
"""
Performs the Alexander-Govern test for equality of means across multiple independent samples with possible heterogeneity of variance.
Args:
samples: 2D list of float values. Each column represents a group/sample; each row an observation.
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 input type and shape
if not isinstance(samples, list) or len(samples) < 2:
return "Invalid input: samples must be a 2D list with at least two rows."
if not all(isinstance(row, list) for row in samples):
return "Invalid input: samples must be a 2D list."
n_cols = len(samples[0])
if n_cols < 2:
return "Invalid input: samples must have at least two columns (groups)."
for row in samples:
if len(row) != n_cols:
return "Invalid input: all rows must have the same number of columns."
for val in row:
if not isinstance(val, (int, float)):
return "Invalid input: all values must be numeric."
# Transpose to columns as groups
groups = [ [row[col] for row in samples] for col in range(n_cols) ]
try:
result = scipy_alexandergovern(*groups)
except Exception as e:
return f"scipy.stats.alexandergovern error: {e}"
stat, pvalue = float(result.statistic), float(result.pvalue)
# Check for nan/inf
if any([isinstance(x, float) and (x != x or x == float('inf') or x == float('-inf')) for x in [stat, pvalue]]):
return "Invalid result: statistic or pvalue is nan or inf."
return [[stat, pvalue]]