Simulation
We will now simulate some data from a Chi-square 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 ( ) distribution, but you are encouraged to change the value of .
> restart: with(plots):
> nu:=5: n:=500:
> sample:=ChisquareS(nu, n):
Remember that when you plot histograms, the number of bins that you select can make a huge difference in the plot.
> num_bins:=20:
> a:=Histogram(sample,0..20,num_bins):
> b:=plot(ChisquarePDF(nu,x),x=0..20,color=black):
> display([a,b],title="Simulated vs. Theoretical");
Now let's compare the simulated mean to the theoretical mean.
> theo_mean:=nu;
> sim_mean:=Mean(sample);
> relative_error:=(sim_mean-theo_mean)/theo_mean;
>