Theorem 8.2.1. Poisson Probability Function.
Assume X measures the number of successes in an interval [0,T] within some Poisson process. Then, with as a needed parameter
for
xxxxxxxxxx
var('x,mu')
assume(x,'integer')
f(x) =e^(-mu)*mu^x/factorial(x)
mu = sum(x*f,x,0,oo).factor()
M2 = sum(x^2*f,x,0,oo).factor()
M3 = sum(x^3*f,x,0,oo).factor()
M4 = sum(x^4*f,x,0,oo).factor()
pretty_print('Mean = ',mu)
v = (M2-mu^2).factor()
pretty_print('Variance = ',v)
stand = sqrt(v)
sk = ((M3 - 3*M2*mu + 2*mu^3)).factor()/stand^3
pretty_print('Skewness = ',sk)
kurt = (M4 - 4*M3*mu + 6*M2*mu^2 -3*mu^4).factor()/stand^4
pretty_print('Kurtosis = ',(kurt-3).factor(),'+3')
xxxxxxxxxx
mu = 3 # the mean must be given
sdev = sqrt(mu) # the formula for the standard deviation
M = mu*6 # the space is infinite but we just go out 6 standard deviations
X = 0:M # part of the space R of the random variable
if(M < 101){
dpois( X, mu, log = FALSE ) # let's print out a bunch of actual probs if M reasonable
}
Ppois = dpois(X, mu ) # create the probability function over X
Psample = rpois(10^6, mu) # to create a histogram, sample a lot
Xtop=max(Psample) # for scaling the x-axis. Shift by 1/2 below.
hist(Psample, prob=TRUE, br=(-1:Xtop)+0.5, col="skyblue2", xlab="X",
main="Poisson Probability Function vs Approximating 'Bell Curve'")
points(X, Ppois, pch=19, col="darkgreen") # to create actual (x,f(x))
Pnormal <- function(X){dnorm(X, mean=mu, sd=sdev)} # to overlap a bell curve
curve(Pnormal, col="red", lwd=2, add=TRUE)