Simulation
We will now simulate some data from a normal 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 Normal(0, 1) distribution, but you are invited to change the parameters.
> restart: with(plots):
> mu:=0: sigma:=1: n:=500:
> sample:=NormalS(mu,sigma^2, n):
Remember that when you plot histograms, the number of bins that you select can make a huge difference in the plot.
> num_bins:=32:
> a:=Histogram(sample,-4..4,num_bins):
> b:=plot(NormalPDF(mu,sigma^2,x),x=-4..4,color=black):
> display([a,b],title="Simulated vs. Theoretical");
Now let's compare the simulated mean to the theoretical mean.
> theo_mean:=mu;
> sim_mean:=Mean(sample);
> difference:=sim_mean-theo_mean;
>