Skip to Content

POISSON_MEANS_TEST

Overview

The POISSON_MEANS_TEST function performs the Poisson means test (E-test) to compare the means of two Poisson distributions. This test is useful for determining whether the observed event rates in two samples are statistically different, accounting for sample sizes and a hypothesized difference in means. The test statistic and p-value are computed using the method described in scipy.stats.poisson_means_test:

E=(k1/n1)(k2/n2)diff(k1/n12)+(k2/n22)E = \frac{(k_1/n_1) - (k_2/n_2) - \text{diff}}{\sqrt{(k_1/n_1^2) + (k_2/n_2^2)}}

where k1k_1 and k2k_2 are the number of events, n1n_1 and n2n_2 are the sample sizes, and diff\text{diff} is the hypothesized difference in means. The function exposes all commonly used parameters and supports the three alternative hypotheses: two-sided, less, and greater. The wrapper simplifies the output to a single-row 2D array for Excel compatibility.

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

Usage

To use the function in Excel:

=POISSON_MEANS_TEST(k_one, n_one, k_two, n_two, [diff], [alternative])
  • k_one (int, required): Number of events observed from distribution 1.
  • n_one (float, required): Size of sample from distribution 1.
  • k_two (int, required): Number of events observed from distribution 2.
  • n_two (float, required): Size of sample from distribution 2.
  • diff (float, optional, default=0.0): Hypothesized difference in means.
  • alternative (str, optional, default=two-sided): Defines the alternative hypothesis (two-sided, less, greater).

The function returns a single-row 2D array [[statistic, pvalue]] if successful, or an error message (string) if the input is invalid. The statistic quantifies the difference between means, and the p-value indicates the probability of observing such a difference under the null hypothesis.

Examples

Example 1: Basic Two-Sided Test

Inputs:

k_onen_onek_twon_twodiffalternative
105.0157.0

Excel formula:

=POISSON_MEANS_TEST(10, 5.0, 15, 7.0)

Expected output:

statisticpvalue
-0.1700.877

Example 2: Greater Alternative

Inputs:

k_onen_onek_twon_twodiffalternative
2010.01010.0greater

Excel formula:

=POISSON_MEANS_TEST(20, 10.0, 10, 10.0, , "greater")

Expected output:

statisticpvalue
1.8260.034

Example 3: Less Alternative with Diff

Inputs:

k_onen_onek_twon_twodiffalternative
52.083.00.5less

Excel formula:

=POISSON_MEANS_TEST(5, 2.0, 8, 3.0, 0.5, "less")

Expected output:

statisticpvalue
-0.4560.348

Example 4: All Arguments Specified

Inputs:

k_onen_onek_twon_twodiffalternative
126.0189.00.0two-sided

Excel formula:

=POISSON_MEANS_TEST(12, 6.0, 18, 9.0, 0.0, "two-sided")

Expected output:

statisticpvalue
0.0001.000

Python Code

from scipy.stats import poisson_means_test as scipy_poisson_means_test from typing import Union def poisson_means_test(k_one: int, n_one: float, k_two: int, n_two: float, diff: float = 0.0, alternative: str = 'two-sided') -> Union[list[list[float]], str]: """ Performs the Poisson means test (E-test) to compare the means of two Poisson distributions. Args: k_one: Number of events observed from distribution 1 (integer). n_one: Size of sample from distribution 1 (float). k_two: Number of events observed from distribution 2 (integer). n_two: Size of sample from distribution 2 (float). diff: Hypothesized difference in means (float, default 0.0). alternative: Defines the alternative hypothesis ('two-sided', 'less', 'greater'). Default is 'two-sided'. Returns: 2D list [[statistic, pvalue]] if successful, or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate input types and values try: k1 = int(k_one) n1 = float(n_one) k2 = int(k_two) n2 = float(n_two) diff_val = float(diff) except Exception: return "Invalid input: k_one, n_one, k_two, n_two, and diff must be numeric." if n1 <= 0 or n2 <= 0: return "Invalid input: n_one and n_two must be positive." if k1 < 0 or k2 < 0: return "Invalid input: k_one and k_two must be non-negative." if alternative not in ['two-sided', 'less', 'greater']: return "Invalid input: alternative must be 'two-sided', 'less', or 'greater'." try: result = scipy_poisson_means_test( k1=k1, n1=n1, k2=k2, n2=n2, diff=diff_val, alternative=alternative ) stat = float(result.statistic) pval = float(result.pvalue) # Disallow nan, inf, -inf if any([ stat is None, pval is None, stat != stat or stat in [float('inf'), float('-inf')], pval != pval or pval in [float('inf'), float('-inf')] ]): return "Invalid output: statistic or pvalue is not a finite number." return [[stat, pval]] except Exception as e: return f"scipy.poisson_means_test error: {e}"

Example Workbook

Link to Workbook

Last updated on