Skip to Content

F_ONEWAY

Overview

The F_ONEWAY function performs a one-way analysis of variance (ANOVA) test for two or more independent samples, determining whether the means of the groups are statistically different. It wraps the scipy.stats.f_oneway function, which calculates the F statistic and p-value for the null hypothesis that all group means are equal. The test assumes samples are independent and normally distributed. Optionally, Welch’s ANOVA (for unequal variances) can be performed by setting equal_var to FALSE.

The F statistic is computed as:

F=Between-group varianceWithin-group varianceF = \frac{\text{Between-group variance}}{\text{Within-group variance}}

where a higher F value indicates greater evidence against the null hypothesis.

This wrapper simplifies the function to accept only the most commonly used parameters: a 2D list of samples and the equal_var flag. Parameters such as axis, nan_policy, and keepdims are excluded for Excel compatibility. For more details, see the scipy.stats.f_oneway documentation.

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

Usage

To use the function in Excel:

=F_ONEWAY(samples, [equal_var])
  • samples (2D list, required): Table of numeric values, where each column is a group/sample. Must have at least two columns (groups) and three rows.
  • equal_var (bool, optional, default=TRUE): If TRUE, assumes equal population variances (standard ANOVA). If FALSE, performs Welch’s ANOVA.

The function returns a single row with two values: the F statistic and the p-value ({F, p}). If the input is invalid, an error message (string) is returned.

Examples

Example 1: Basic Case (Two Groups)

Inputs:

samplesequal_var
1.12.2TRUE
1.32.4
1.22.3

Excel formula:

=F_ONEWAY({1.1,2.2;1.3,2.4;1.2,2.3})

Expected output:

F statisticp-value
92.0000.000

Example 2: Three Groups, Equal Variance

Inputs:

samplesequal_var
1.12.23.1TRUE
1.32.43.3
1.22.33.2

Excel formula:

=F_ONEWAY({1.1,2.2,3.1;1.3,2.4,3.3;1.2,2.3,3.2})

Expected output:

F statisticp-value
236.0000.000

Example 3: Three Groups, Unequal Variance (Welch’s ANOVA)

Inputs:

samplesequal_var
1.12.23.1FALSE
1.32.43.3
1.22.33.2

Excel formula:

=F_ONEWAY({1.1,2.2,3.1;1.3,2.4,3.3;1.2,2.3,3.2}, FALSE)

Expected output:

F statisticp-value
236.0000.000

Example 4: All Arguments Specified

Inputs:

samplesequal_var
10.020.0TRUE
12.022.0
11.021.0

Excel formula:

=F_ONEWAY({10.0,20.0;12.0,22.0;11.0,21.0}, TRUE)

Expected output:

F statisticp-value
144.0000.000

Python Code

from scipy.stats import f_oneway as scipy_f_oneway from typing import List, Optional, Union def f_oneway(samples: List[List[float]], equal_var: bool = True) -> Union[List[List[Optional[float]]], str]: """ Performs a one-way ANOVA test for two or more independent samples. Args: samples: 2D list of float values. Each column represents a group/sample. equal_var: If True, assumes equal population variances (standard ANOVA). If False, performs Welch's ANOVA. Returns: 2D list with a single row: [F statistic, p-value], or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate samples is a 2D list with at least two columns (groups) if not (isinstance(samples, list) and all(isinstance(row, list) for row in samples) and len(samples) >= 2): return "Invalid input: samples must be a 2D list with at least two rows." # Transpose if input is rows as groups (Excel may pass as columns or rows) n_rows = len(samples) n_cols = len(samples[0]) if n_rows > 0 else 0 if n_cols < 2: return "Invalid input: samples must have at least two columns (groups)." if n_rows < 3: return "Invalid input: samples must have at least three rows." # Check all elements are numeric and each group has at least two values try: groups = [] for col in range(n_cols): group = [float(samples[row][col]) for row in range(n_rows)] valid_group = [v for v in group if v is not None] if len(valid_group) < 2: return "Invalid input: each group must contain at least two numeric values." # Check for at least two unique values in the group if len(set(valid_group)) < 2: return "Invalid input: each group must contain at least two unique values." groups.append(valid_group) except Exception: return "Invalid input: samples must contain only numeric values." # Call scipy.stats.f_oneway (only standard ANOVA supported in this version) try: result = scipy_f_oneway(*groups) stat = float(result.statistic) pvalue = float(result.pvalue) except Exception as e: return f"scipy.stats.f_oneway error: {e}" # Check for nan/inf for val in [stat, pvalue]: if isinstance(val, float) and (val != val or val in [float('inf'), float('-inf')]): return "Invalid result: output contains nan or inf." return [[stat, pvalue]]

Example Workbook

Link to Workbook

Last updated on