Simulation
We will now simulate some data from a Beta distribution in order to compare the sampling distribution to the theoretical distribution. The next portion of code will simulate a random sample of size 500 from a Beta(3,4) distribution, but you are encouraged to change the values of and .
> restart: with(plots,display):
> f:=(alpha,beta,x)->GAMMA(alpha+beta)/(GAMMA(alpha)*GAMMA(beta))*x^(alpha-1)*(1-x)^(beta-1);
> alpha:=3: beta:=4: n:=500:
> sample:=BetaS(alpha-1, beta-1, n):
Remember that when you plot histograms, the number of bins that you select can make a significant difference in the plot.
> num_bins:=20:
> a:=Histogram(sample,0..1,num_bins):
> b:=plot(f(alpha,beta,x),x=0..1,color=black):
> display([a,b],title="Simulated vs. Theoretical");
Now let's compare the simulated mean to the theoretical mean.
> theo_mean:=alpha/(alpha+beta);
> sim_mean:=Mean(sample);
> relative_error:=(sim_mean-theo_mean)/theo_mean;
>