Simulation
We will now simulate some data from an Exponential( ) 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 .
> 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");
Now let's compare the simulated mean to the theoretical mean.
> theo_mean:=1/theta;
> sim_mean:=Mean(sample);
> relative_error:=(sim_mean-theo_mean)/theo_mean;