Skip to Content

QUANTILE_TEST

Overview

The QUANTILE_TEST function performs a statistical test of the null hypothesis that a specified quantile of the population is equal to a given value, using the sample data provided. This is useful for determining whether the observed quantile (such as the median) of a dataset significantly differs from a hypothesized value. The function is based on the SciPy quantile_test method, which uses the binomial distribution to compute the p-value for the test statistic.

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

Usage

To use the function in Excel:

=QUANTILE_TEST(x, [q], [p])
  • x (2D list, required): Sample data. Must contain at least two elements (as a column or row vector).
  • q (float, optional, default=0): Hypothesized value of the quantile.
  • p (float, optional, default=0.5): Probability associated with the quantile (e.g., 0.5 for median).

The function returns a 2D list with two elements: the test statistic and the p-value. If the input is invalid, an error message (string) is returned.

Examples

Example 1: Median Test (default p=0.5)

Inputs:

xqp
100.5
2
3
4
5

Excel formula:

=QUANTILE_TEST({1;2;3;4;5})

Expected output:

Test StatisticP-value
0.00.0625

Example 2: Test for quantile = 3

Inputs:

xqp
130.5
2
3
4
5

Excel formula:

=QUANTILE_TEST({1;2;3;4;5}, 3)

Expected output:

Test StatisticP-value
3.01.0

Example 3: Lower quantile (p=0.25)

Inputs:

xqp
120.25
2
3
4
5

Excel formula:

=QUANTILE_TEST({1;2;3;4;5}, 2, 0.25)

Expected output:

Test StatisticP-value
1.01.0

Example 4: Upper quantile (p=0.75)

Inputs:

xqp
140.75
2
3
4
5

Excel formula:

=QUANTILE_TEST({1;2;3;4;5}, 4, 0.75)

Expected output:

Test StatisticP-value
4.01.0

Python Code

from scipy.stats import quantile_test as scipy_quantile_test def quantile_test(x, q=0, p=0.5): """ Perform a quantile test and compute a confidence interval of the quantile. Args: x: 2D list. Sample data (must contain two or more elements). q: float, optional. Hypothesized value of the quantile (default 0). p: float, optional. Probability associated with the quantile (default 0.5). Returns: 2D list. Test statistic and p-value, or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Flatten x to 1D list try: if isinstance(x, (int, float)): return "Invalid input: x must be a 2D list with at least two elements." flat_x = [] for row in x: if isinstance(row, list): flat_x.extend(row) else: flat_x.append(row) if len(flat_x) < 2: return "Invalid input: x must contain at least two elements." flat_x = [float(val) for val in flat_x] except Exception: return "Invalid input: x must be a 2D list of numbers." try: q_val = float(q) p_val = float(p) except Exception: return "Invalid input: q and p must be numbers." try: result = scipy_quantile_test(flat_x, q=q_val, p=p_val) # result.statistic, result.pvalue return [[float(result.statistic), float(result.pvalue)]] except Exception as e: return f"scipy.stats.quantile_test error: {e}"

Example Workbook

Link to Workbook

Last updated on