Simulation
We will now simulate some data from a geometric 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 Geometric(0.5) distribution, but you are invited to change the parameters.
> restart: with(plots):
> p:=0.5: numsim:=500:
> sample:=GeometricS(p,numsim):
> a:=Histogram(sample,0.5..10+0.5,10):
> b:=ProbHist(GeometricPDF(p,x),1..10,10):
> display([a,b],title="Simulated vs. Theoretical");
Now let's compare the simulated mean to the theoretical mean.
> theo_mean:=1/p;
> sim_mean:=evalf(Mean(sample));
> relative_error:=(sim_mean-theo_mean)/theo_mean;