Simulation
We will now simulate some data from a t 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 t (5) distribution, but you are encouraged to change the degrees of freedom.
> restart: with(plots):
> nu:=5: n:=500:
> sample:=TS(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:=42:
> a:=Histogram(sample,-7..7,num_bins):
> b:=plot(TPDF(nu,x),x=-7..7,color=black):
> display([a,b],title="Simulated vs. Theoretical");
Now let's compare the simulated mean to the theoretical mean.
> theo_mean:=0;
> sim_mean:=Mean(sample);
> difference:=(sim_mean-theo_mean);