F_DIST

Overview

The F_DIST function provides a unified interface to the F-distribution (also known as the Fisher–Snedecor distribution), a continuous probability distribution that arises as the ratio of two independent chi-squared random variables, each divided by their respective degrees of freedom. Named after statisticians Ronald Fisher and George W. Snedecor, the F-distribution is fundamental in statistical hypothesis testing, particularly in analysis of variance (ANOVA) and F-tests for comparing variances.

The F-distribution with d_1 (numerator) and d_2 (denominator) degrees of freedom is defined as the distribution of the ratio:

X = \frac{U_1 / d_1}{U_2 / d_2}

where U_1 and U_2 are independent chi-squared random variables with d_1 and d_2 degrees of freedom respectively. The probability density function (PDF) for x > 0 is:

f(x; d_1, d_2) = \frac{1}{B(d_1/2, d_2/2)} \left(\frac{d_1}{d_2}\right)^{d_1/2} x^{d_1/2 - 1} \left(1 + \frac{d_1}{d_2}x\right)^{-(d_1 + d_2)/2}

where B is the beta function. The distribution mean exists only when d_2 > 2 and equals d_2 / (d_2 - 2), while the variance is defined for d_2 > 4.

This implementation uses SciPy’s scipy.stats.f module, which supports location and scale parameters for shifting and scaling the distribution. The function provides access to multiple statistical methods: probability density function (PDF), cumulative distribution function (CDF), inverse CDF (quantiles), survival function, inverse survival function, and distribution statistics (mean, median, variance, standard deviation).

Common applications include testing whether two population variances are equal, comparing model fit in regression analysis, and assessing the significance of factors in ANOVA. For the generalized case with non-zero noncentrality parameters, see the noncentral F-distribution. Additional background is available on Wikipedia.

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

Excel Usage

=F_DIST(value, dfn, dfd, loc, scale, f_dist_method)
  • value (float, optional, default: null): For pdf/cdf/sf, the value x at which to evaluate (must be > 0). For icdf/isf, the probability q (must be between 0 and 1). Not used for mean/median/var/std.
  • dfn (float, optional, default: 1): Numerator degrees of freedom. Must be > 0.
  • dfd (float, optional, default: 1): Denominator degrees of freedom. Must be > 0.
  • loc (float, optional, default: 0): Location parameter.
  • scale (float, optional, default: 1): Scale parameter. Must be > 0.
  • f_dist_method (str, optional, default: “pdf”): The statistical method to compute.

Returns (float): Result of the requested method, or str error message if invalid.

Examples

Example 1: Demo case 1

Inputs:

value dfn dfd loc scale f_dist_method
2 5 10 0 1 pdf

Excel formula:

=F_DIST(2, 5, 10, 0, 1, "pdf")

Expected output:

0.162

Example 2: Demo case 2

Inputs:

value dfn dfd loc scale f_dist_method
2 5 10 0 1 cdf

Excel formula:

=F_DIST(2, 5, 10, 0, 1, "cdf")

Expected output:

0.8358

Example 3: Demo case 3

Inputs:

value dfn dfd loc scale f_dist_method
0.8358 5 10 0 1 icdf

Excel formula:

=F_DIST(0.8358, 5, 10, 0, 1, "icdf")

Expected output:

2

Example 4: Demo case 4

Inputs:

dfn dfd loc scale f_dist_method
5 10 0 1 mean

Excel formula:

=F_DIST(5, 10, 0, 1, "mean")

Expected output:

1.25

Python Code

from scipy.stats import f as scipy_f
import math

def f_dist(value=None, dfn=1, dfd=1, loc=0, scale=1, f_dist_method='pdf'):
    """
    Unified interface to the main methods of the F-distribution, including PDF, CDF, inverse CDF, survival function, and distribution statistics.

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

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

    Args:
        value (float, optional): For pdf/cdf/sf, the value x at which to evaluate (must be > 0). For icdf/isf, the probability q (must be between 0 and 1). Not used for mean/median/var/std. Default is None.
        dfn (float, optional): Numerator degrees of freedom. Must be > 0. Default is 1.
        dfd (float, optional): Denominator degrees of freedom. Must be > 0. Default is 1.
        loc (float, optional): Location parameter. Default is 0.
        scale (float, optional): Scale parameter. Must be > 0. Default is 1.
        f_dist_method (str, optional): The statistical method to compute. Valid options: PDF, CDF, ICDF, SF, ISF, Mean, Median, Var, Std. Default is 'pdf'.

    Returns:
        float: Result of the requested method, or str error message if invalid.
    """
    valid_methods = {'pdf', 'cdf', 'icdf', 'sf', 'isf', 'mean', 'median', 'var', 'std'}

    if not isinstance(f_dist_method, str):
        return f"Invalid method: {f_dist_method}. Must be a string."

    method = f_dist_method.lower()
    if method not in valid_methods:
        return f"Invalid method: {f_dist_method}. Must be one of {', '.join(sorted(valid_methods))}."

    try:
        dfn = float(dfn)
        dfd = float(dfd)
        loc = float(loc)
        scale = float(scale)
    except (ValueError, TypeError):
        return "Invalid input: dfn, dfd, loc, and scale must be numbers."

    if dfn <= 0 or dfd <= 0:
        return "Invalid input: dfn and dfd must be > 0."
    if scale <= 0:
        return "Invalid input: scale must be > 0."

    # Methods that require 'value'
    if method in {'pdf', 'cdf', 'icdf', 'sf', 'isf'}:
        if value is None:
            return f"Invalid input: missing required argument 'value' for method '{method}'."
        try:
            value = float(value)
        except (ValueError, TypeError):
            return "Invalid input: value must be a number."

        if method in {'pdf', 'cdf', 'sf'} and value < 0:
            return "Invalid input: value must be >= 0 for this method."

        if method in {'icdf', 'isf'} and not (0 <= value <= 1):
            return "Invalid input: value (probability) must be between 0 and 1."

    try:
        dist = scipy_f(dfn, dfd, loc=loc, scale=scale)

        if method == 'pdf':
            result = dist.pdf(value)
        elif method == 'cdf':
            result = dist.cdf(value)
        elif method == 'sf':
            result = dist.sf(value)
        elif method == 'icdf':
            result = dist.ppf(value)
        elif method == 'isf':
            result = dist.isf(value)
        elif method == 'mean':
            result = dist.mean()
        elif method == 'median':
            result = dist.median()
        elif method == 'var':
            result = dist.var()
        elif method == 'std':
            result = dist.std()
        else:
            return f"Internal error: method '{method}' not handled."

    except Exception as e:
        return f"scipy.stats.f error: {str(e)}"

    if isinstance(result, float):
        if math.isnan(result):
            return "Result is NaN"
        if math.isinf(result):
            return "inf" if result > 0 else "-inf"

    return float(result)

Online Calculator