Friday, February 19, 2010

Checking an exponential approximation


In the previous post about the Poisson approximation to the binomial distribution, we said that "since n is large and p is small":
(1-p)n ≈ e-np


I wanted to take a look at the accuracy of the approximation. In the plot at the top, p varies from 0.005 to 0.03 as shown on the x-axis, for values of n in the series 10,30,100,300 (red, blue, purple, gray). The first thing to observe is that, if p is small, the approximation is very good. The error is < 1% for all values of p < 0.25 if n is equal to 10 or 30. However, it is not necessary that n be large. In fact, the error is much worse for n = 100 or 300. Still, for 100 trials with p = 0.01, the error is < 1%.

R code:

f <- function(p,n) {
left = (1-p)**n
right = exp(-p*n)
(right - left)/left }

plot(1,type='n',
xlim=c(0,0.03),ylim=c(0,0.10),
xlab='p',ylab='error')
p = seq(0.005,0.04,by=0.005)
points(p,f(p,n=10),pch=16,cex=3,col='red')
points(p,f(p,n=30),pch=16,cex=3,col='dodgerblue')
points(p,f(p,n=100),pch=16,cex=3,col='purple')
points(p,f(p,n=300),pch=16,cex=3,col='gray60')