HOMOSCEDASTICITY

Homoscedasticity tests evaluate whether multiple groups have equal variances.

Equal-variance assumptions are commonly required for classical ANOVA and related parametric procedures. Pingouin provides a unified interface for methods such as Levene and Bartlett tests.

This wrapper consumes tabular data and returns the resulting variance-homogeneity test table.

Excel Usage

=HOMOSCEDASTICITY(data, dv, group, method, alpha)
  • data (list[list], required): Input table where the first row contains column names.
  • dv (str, required): Name of the dependent-variable column.
  • group (str, required): Name of the grouping column.
  • method (str, optional, default: “levene”): Variance test method (for example levene or bartlett).
  • alpha (float, optional, default: 0.05): Significance level for decision threshold.

Returns (list[list]): 2D table containing homoscedasticity test results.

Example 1: Levene homoscedasticity test

Inputs:

data dv group
score grp score grp
5 A
5.2 A
5.1 A
6 B
6.3 B
6.1 B
7.1 C
7 C
7.2 C

Excel formula:

=HOMOSCEDASTICITY({"score","grp";5,"A";5.2,"A";5.1,"A";6,"B";6.3,"B";6.1,"B";7.1,"C";7,"C";7.2,"C"}, "score", "grp")

Expected output:

W pval equal_var
0.2 0.823975 true
Example 2: Bartlett homoscedasticity test

Inputs:

data dv group method
x g x g bartlett
10 G1
10.2 G1
9.8 G1
12.1 G2
12.2 G2
11.9 G2
13.5 G3
13.7 G3
13.4 G3

Excel formula:

=HOMOSCEDASTICITY({"x","g";10,"G1";10.2,"G1";9.8,"G1";12.1,"G2";12.2,"G2";11.9,"G2";13.5,"G3";13.7,"G3";13.4,"G3"}, "x", "g", "bartlett")

Expected output:

T pval equal_var
0.16646 0.920139 true
Example 3: Custom alpha level

Inputs:

data dv group alpha
measure kind measure kind 0.01
2 K1
2.1 K1
1.9 K1
2.8 K2
2.9 K2
2.7 K2
3.6 K3
3.5 K3
3.7 K3

Excel formula:

=HOMOSCEDASTICITY({"measure","kind";2,"K1";2.1,"K1";1.9,"K1";2.8,"K2";2.9,"K2";2.7,"K2";3.6,"K3";3.5,"K3";3.7,"K3"}, "measure", "kind", 0.01)

Expected output:

W pval equal_var
5.80668e-30 1 true
Example 4: Mild variance differences

Inputs:

data dv group
y cat y cat
21 C1
21.1 C1
20.9 C1
22 C2
22.4 C2
21.8 C2
23 C3
23.5 C3
22.7 C3

Excel formula:

=HOMOSCEDASTICITY({"y","cat";21,"C1";21.1,"C1";20.9,"C1";22,"C2";22.4,"C2";21.8,"C2";23,"C3";23.5,"C3";22.7,"C3"}, "y", "cat")

Expected output:

W pval equal_var
0.875 0.464033 true

Python Code

import pandas as pd
from pingouin import homoscedasticity as pg_homoscedasticity

def homoscedasticity(data, dv, group, method='levene', alpha=0.05):
    """
    Test equality of variances across groups using Pingouin.

    See: https://pingouin-stats.org/build/html/generated/pingouin.homoscedasticity.html

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

    Args:
        data (list[list]): Input table where the first row contains column names.
        dv (str): Name of the dependent-variable column.
        group (str): Name of the grouping column.
        method (str, optional): Variance test method (for example levene or bartlett). Default is 'levene'.
        alpha (float, optional): Significance level for decision threshold. Default is 0.05.

    Returns:
        list[list]: 2D table containing homoscedasticity test results.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        def build_dataframe(table):
            table = to2d(table)
            if not isinstance(table, list) or not table or not all(isinstance(row, list) for row in table):
                return None, "Error: data must be a non-empty 2D list"
            if len(table) < 2:
                return None, "Error: data must include a header row and at least one data row"

            headers = [str(h).strip() for h in table[0]]
            if any(h == "" for h in headers):
                return None, "Error: header row contains empty column names"
            if len(set(headers)) != len(headers):
                return None, "Error: header row contains duplicate column names"

            rows = []
            for row in table[1:]:
                if len(row) != len(headers):
                    return None, "Error: all data rows must match header width"
                rows.append([None if cell == "" else cell for cell in row])

            return pd.DataFrame(rows, columns=headers), None

        def dataframe_to_2d(df):
            out = [list(df.columns)]
            for values in df.itertuples(index=False, name=None):
                row = []
                for value in values:
                    if pd.isna(value):
                        row.append("")
                    elif isinstance(value, bool):
                        row.append(value)
                    elif isinstance(value, (int, float)):
                        row.append(float(value))
                    else:
                        row.append(str(value))
                out.append(row)
            return out

        frame, error = build_dataframe(data)
        if error:
            return error

        if dv not in frame.columns:
            return f"Error: dv column '{dv}' not found"
        if group not in frame.columns:
            return f"Error: group column '{group}' not found"

        result = pg_homoscedasticity(data=frame, dv=dv, group=group, method=method, alpha=float(alpha))
        return dataframe_to_2d(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input table where the first row contains column names.
Name of the dependent-variable column.
Name of the grouping column.
Variance test method (for example levene or bartlett).
Significance level for decision threshold.