Simulation

We will now simulate some data from an Exponential( [Maple Math] ) 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 an Exponential(1) distribution, but you are invited to change the value of [Maple Math] .

> restart: with(plots):

> theta:=1: n:=500:

> sample:=ExponentialS(theta, n):

Remember that when you plot histograms, the number of bins that you select can make a huge difference in the plot.

> num_bins:=28:

> a:=Histogram(sample,0..7,num_bins):

> b:=plot(ExponentialPDF(theta,x),x=0..7,color=black):

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

[Maple Plot]

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

> theo_mean:=1/theta;

[Maple Math]

> sim_mean:=Mean(sample);

[Maple Math]

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

[Maple Math]