Simulation

We will now simulate some data from a hypergeometric 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 Hypergeometric ( G = 50, B = 25, n = 30) distribution, but you are invited to change the parameters.

> restart: with(plots):

> G:=50: B:=25: n:=30: numsim:=500:

>

> sample:=HypergeometricS(G, B, n,numsim):

> a:=Histogram(sample,-0.5..30+0.5,31):

> b:=ProbHist(HypergeometricPDF(G,B,n,g),0..30,30):

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

[Maple Plot]

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

> theo_mean:=n*G/(G+B);

[Maple Math]

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

[Maple Math]

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

[Maple Math]