Simulation

We will now simulate some data from a poisson distribution in order to compare the sampling distribution to the theoretical distribution. The next bit of code will simulate a random sample of size 500 from a Poisson(5) distribution, but you are invited to change the value of lambda.

>

> restart: with(plots):

> lambda:=5: numsim:=500:

> sample:=PoissonS(lambda,numsim):

> a:=Histogram(sample,-0.5..15+0.5,16):

> b:=ProbHist(PoissonPDF(lambda,x),0..16,17):

> display([a,b],title="Simulated(red) vs. Theoretical(blue)");

[Maple Plot]

Now let's compare the simulated mean to the theoretical mean.

> theo_mean:=lambda;

[Maple Math]

> sim_mean:=evalf(Mean(sample));

[Maple Math]

> relative_error:=(sim_mean-theo_mean)/theo_mean;

[Maple Math]