POISSON_MEANS_TEST
Overview
The POISSON_MEANS_TEST function performs the Poisson means test, also known as the E-test, to compare the rate parameters of two independent Poisson distributions. This test is particularly useful when analyzing count data such as defect rates, event occurrences, or incident counts between two groups or time periods.
The Poisson distribution models the probability of a given number of events occurring in a fixed interval when events happen at a constant average rate and independently of each other. Common applications include counting radioactive decays, customer arrivals, manufacturing defects, or rare disease occurrences.
This implementation uses SciPy’s poisson_means_test function. Given the number of events k_1 and k_2 observed in samples of sizes n_1 and n_2 respectively, the test evaluates the null hypothesis:
H_0: \lambda_1 - \lambda_2 = \text{diff}
where \lambda_1 and \lambda_2 are the true rate parameters (mean events per unit) of the two Poisson distributions, and diff is the hypothesized difference (default is 0, testing for equality of rates).
A key advantage of the E-test is its superior statistical power for small sample sizes compared to alternatives like the C-test (sometimes called the Poisson exact test). This makes it particularly valuable in situations where sampling is expensive or difficult, such as quality control, epidemiological studies, or rare event analysis. The methodology is based on the work of Krishnamoorthy & Thomson (2004), “A more powerful test for comparing two Poisson means”, published in the Journal of Statistical Planning and Inference.
The function returns a test statistic and a p-value. A small p-value (typically < 0.05) indicates evidence against the null hypothesis, suggesting that the difference in Poisson rates is statistically significant.
This example function is provided as-is without any representation of accuracy.
Excel Usage
=POISSON_MEANS_TEST(k_one, n_one, k_two, n_two, diff, pmt_alternative)
k_one(int, required): Number of events observed from distribution 1 (non-negative integer).n_one(float, required): Size of sample from distribution 1 (positive).k_two(int, required): Number of events observed from distribution 2 (non-negative integer).n_two(float, required): Size of sample from distribution 2 (positive).diff(float, optional, default: 0): Hypothesized difference in means under the null hypothesis.pmt_alternative(str, optional, default: “two-sided”): Defines the alternative hypothesis.
Returns (list[list]): 2D list [[statistic, p_value]], or error message string.
Examples
Example 1: Basic two-sided test
Inputs:
| k_one | n_one | k_two | n_two |
|---|---|---|---|
| 10 | 5 | 15 | 7 |
Excel formula:
=POISSON_MEANS_TEST(10, 5, 15, 7)
Expected output:
| Result | |
|---|---|
| -0.17 | 0.8768 |
Example 2: Greater alternative hypothesis
Inputs:
| k_one | n_one | k_two | n_two | pmt_alternative |
|---|---|---|---|---|
| 20 | 10 | 10 | 10 | greater |
Excel formula:
=POISSON_MEANS_TEST(20, 10, 10, 10, "greater")
Expected output:
| Result | |
|---|---|
| 1.8257 | 0.0344 |
Example 3: Less alternative with hypothesized difference
Inputs:
| k_one | n_one | k_two | n_two | diff | pmt_alternative |
|---|---|---|---|---|---|
| 5 | 2 | 8 | 3 | 0.5 | less |
Excel formula:
=POISSON_MEANS_TEST(5, 2, 8, 3, 0.5, "less")
Expected output:
| Result | |
|---|---|
| -0.4558 | 0.3483 |
Example 4: All arguments explicitly specified
Inputs:
| k_one | n_one | k_two | n_two | diff | pmt_alternative |
|---|---|---|---|---|---|
| 12 | 6 | 18 | 9 | 0 | two-sided |
Excel formula:
=POISSON_MEANS_TEST(12, 6, 18, 9, 0, "two-sided")
Expected output:
| Result | |
|---|---|
| 0 | 1 |
Python Code
import math
from scipy.stats import poisson_means_test as scipy_poisson_means_test
def poisson_means_test(k_one, n_one, k_two, n_two, diff=0, pmt_alternative='two-sided'):
"""
Performs the Poisson means test (E-test) to compare the means of two Poisson distributions.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson_means_test.html
This example function is provided as-is without any representation of accuracy.
Args:
k_one (int): Number of events observed from distribution 1 (non-negative integer).
n_one (float): Size of sample from distribution 1 (positive).
k_two (int): Number of events observed from distribution 2 (non-negative integer).
n_two (float): Size of sample from distribution 2 (positive).
diff (float, optional): Hypothesized difference in means under the null hypothesis. Default is 0.
pmt_alternative (str, optional): Defines the alternative hypothesis. Valid options: Two-sided, Less, Greater. Default is 'two-sided'.
Returns:
list[list]: 2D list [[statistic, p_value]], or error message string.
"""
# 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 pmt_alternative not in ['two-sided', 'less', 'greater']:
return "Invalid input: pmt_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=pmt_alternative
)
stat = float(result.statistic)
pval = float(result.pvalue)
if not math.isfinite(stat) or not math.isfinite(pval):
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}"