ALEXANDERGOVERN

Overview

The ALEXANDERGOVERN function performs the Alexander-Govern test, a statistical hypothesis test for comparing the equality of means across two or more independent sample groups when the assumption of equal variances (homoscedasticity) cannot be met. This makes it a robust alternative to the traditional one-way ANOVA (f_oneway) when group variances differ.

The test was introduced by Ralph A. Alexander and Diane M. Govern in their 1994 paper “A New and Simpler Approximation for ANOVA under Variance Heterogeneity” published in the Journal of Educational Statistics. Their approach provides a simpler computational method compared to earlier heteroscedastic ANOVA alternatives like the Welch or Brown-Forsythe tests, while maintaining good Type I error control and statistical power.

The Alexander-Govern test relies on the following assumptions:

  1. The samples are independent of one another
  2. Each sample is drawn from a normally distributed population
  3. Variances across groups may be unequal (heteroscedasticity is permitted)

The test computes a statistic (denoted A) that follows an approximate chi-squared distribution with k - 1 degrees of freedom, where k is the number of groups being compared. The resulting p-value indicates the probability of observing such an extreme test statistic under the null hypothesis that all group means are equal.

This implementation uses the scipy.stats.alexandergovern function from the SciPy library. The function returns both the test statistic and the associated p-value. A low p-value (typically below 0.05) suggests evidence against the null hypothesis, indicating that at least one group mean differs significantly from the others.

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

Excel Usage

=ALEXANDERGOVERN(samples)
  • samples (list[list], required): 2D array where each column represents a sample group to compare. Must have at least two columns and two rows.

Returns (list[list]): 2D list [[statistic, p_value]], or error message string.

Examples

Example 1: Demo case 1

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:

Result
15.0737 0.0001

Example 2: Demo case 2

Inputs:

samples
1.2 2.3 3.1
1.5 2.1 3.2
1.3 2.2 3
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;1.4,2.4,3.3})

Expected output:

Result
22.51 0.00001

Example 3: Demo case 3

Inputs:

samples
10 10.1
10.2 10
10.1 10.2
10 10.1

Excel formula:

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

Expected output:

Result
0.1323 0.716

Example 4: Demo case 4

Inputs:

samples
1 10
1.1 10.1
0.9 9.9
1.2 10.2

Excel formula:

=ALEXANDERGOVERN({1,10;1.1,10.1;0.9,9.9;1.2,10.2})

Expected output:

Result
40.8114 0

Python Code

from scipy.stats import alexandergovern as scipy_alexandergovern
import math

def alexandergovern(samples):
    """
    Performs the Alexander-Govern test for equality of means across multiple independent samples with possible heterogeneity of variance.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.alexandergovern.html

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

    Args:
        samples (list[list]): 2D array where each column represents a sample group to compare. Must have at least two columns and two rows.

    Returns:
        list[list]: 2D list [[statistic, p_value]], or error message string.
    """
    try:
      # Validate input type and structure
      if not isinstance(samples, list):
        return "Error: samples must be a 2D list."

      if len(samples) < 2:
        return "Error: samples must have at least two rows."

      if not all(isinstance(row, list) for row in samples):
        return "Error: samples must be a 2D list with list rows."

      n_cols = len(samples[0])
      if n_cols < 2:
        return "Error: samples must have at least two columns (groups)."

      # Validate consistent column count and numeric values
      for i, row in enumerate(samples):
        if len(row) != n_cols:
          return f"Error: row {i} has {len(row)} columns, expected {n_cols}."
        for j, val in enumerate(row):
          if not isinstance(val, (int, float)):
            return f"Error: non-numeric value at row {i}, column {j}."
          if math.isnan(val) or math.isinf(val):
            return f"Error: NaN or Inf value at row {i}, column {j}."

      # Transpose: convert columns to groups
      groups = [[row[col] for row in samples] for col in range(n_cols)]

      # Perform the Alexander-Govern test
      result = scipy_alexandergovern(*groups)

      # Extract and validate results
      stat = float(result.statistic)
      pvalue = float(result.pvalue)

      # Check for invalid results
      if math.isnan(stat) or math.isinf(stat):
        return "Error: test statistic is NaN or Inf."
      if math.isnan(pvalue) or math.isinf(pvalue):
        return "Error: p-value is NaN or Inf."

      return [[stat, pvalue]]
    except Exception as e:
      return f"Error: {str(e)}"

Online Calculator