Skip to Content

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:

AG=j=1kwj(xˉjxˉ)2j=1kwjsj2/njAG = \frac{\sum_{j=1}^k w_j (\bar{x}_j - \bar{x})^2}{\sum_{j=1}^k w_j s_j^2 / n_j}

where wjw_j is the weight for group jj, xˉj\bar{x}_j is the mean of group jj, xˉ\bar{x} is the overall mean, sj2s_j^2 is the variance of group jj, and njn_j is the sample size of group jj.

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.22.3
1.52.1
1.32.2
1.42.4

Excel formula:

=ALEXANDERGOVERN({1.2,2.3;1.5,2.1;1.3,2.2;1.4,2.4})

Expected output:

statisticpvalue
15.0740.000

Example 2: Three Groups

Inputs:

samples
1.22.33.1
1.52.13.2
1.32.23.0
1.42.43.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:

statisticpvalue
22.5100.000

Example 3: Groups with Close Means

Inputs:

samples
10.010.1
10.210.0
10.110.2
10.010.1

Excel formula:

=ALEXANDERGOVERN({10.0,10.1;10.2,10.0;10.1,10.2;10.0,10.1})

Expected output:

statisticpvalue
0.1320.716

Example 4: Groups with Different Variance

Inputs:

samples
1.010.0
1.110.1
0.99.9
1.210.2

Excel formula:

=ALEXANDERGOVERN({1.0,10.0;1.1,10.1;0.9,9.9;1.2,10.2})

Expected output:

statisticpvalue
40.8110.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]]

Example Workbook

Link to Workbook

Last updated on