Comparing counts

R
Published

December 6, 2024

Description of problem

  • Two random variables \(X_1\) and \(X_2\) with realiziations \(x_1\) and \(x_2\), each following a Poisson distribution with rates \(\lambda_1\) and \(\lambda_2\)
  • Null hypothesis: \(\lambda_1 = \lambda_2\)

Approximate, naive test

We can construct an approximate, pragmatic statistical test. The test statistic \(k = x_2 - x_1\) follows approximately (asymptotically with growing \(\lambda_1\) and \(\lambda_2\)) a normal distribution with \(\mu = 0\) and \(\sigma = \sqrt{x_1 + x_2}\).

x_1 <- 1500
x_2 <- 1600
k <- x_1 - x_2
sigma <- sqrt(x_1 + x_2)
(p_value <- 2 * pnorm(k, mean = 0, sd = sigma))
[1] 0.07248609

Exact test

R offers an exact test.

poisson.test(c(x_1, x_2))

    Comparison of Poisson rates

data:  c(x_1, x_2) time base: 1
count1 = 1500, expected count1 = 1550, p-value = 0.07537
alternative hypothesis: true rate ratio is not equal to 1
95 percent confidence interval:
 0.8731506 1.0065506
sample estimates:
rate ratio 
    0.9375 

Conclusion

It may be surprising – but measurement of two counts for different conditions can be enough in order to test for equality of event rates.