DO some work (MATLAB) which generates exponential random variables, and use it t
ID: 2266851 • Letter: D
Question
DO some work
(MATLAB) which generates exponential random variables, and use it to test the Central Limit Theorem as follows. For various values of n (say, 5, 10, 20, 50, 100, 1000), generate samples of the random variable Mn = 1/n iny sum Xi where Xi are iid exponential random variables. A very simple method for generating exponential random variables is given on page 196 of the textbook (read that section). Plot the discretized CDF for Mn (an approximation of the CDF using discrete bins) for each n superimposed on the theoretical Gaussian CDF according to the Central Limit Theorem (or plot them next to each other). Calculate the sample mean and variance according to the material in the book and compare these to the theoretical values. Comment briefly on your results. Show all graphs and calculations. Include a copy of your code. Remember, you will need to generate a large number of samples of Mn for each n in order to get decent histograms. I suggest at least 100+ samples. 100 samples of M1000 require 100,000 exponential samples. You may choose any mean and variance you want for your exponential random numbers, but keep these fixed for all samples so that the results are comparable. Using the program written for the previous problem, repeat the whole experiment, but now choose a random mean and variance for each exponential sample. Thus, the Mn now will not be sums of identically distributed random variables. Show your results and comment. For this case, make sure that the distributions you use to choose your mean and variance at each sample are xed throughout. Write the code in MATLAB.
Explanation / Answer
Central Limit Theorem
N=10000;
Nb_bins=30;
type='exp';
parameter1=1;
parameter2=2;
x=zeros(1,N);
user_interface='';
number_of_variables=0;
fprintf('-------------------------- ');
fprintf('| Illustration of the | ');
fprintf('| CLT theorem | ');
fprintf('-------------------------- ');
while strcmp(user_interface,'q')==0
switch type
case 'exp'
random_vector=random('exp',parameter1,1,N);
original_distribution_mean=(1/parameter1);
original_distribution_var=1/(parameter1^2);
distrib_name='exponential';
case 'unif'
random_vector=random('unif',parameter1,parameter2,1,N);
original_distribution_mean=0.5*(parameter2+parameter1);
original_distribution_var=(1/12)*(parameter2-parameter1)^2;
distrib_name='uniform';
case 'chi2'
random_vector=random('chi2',parameter1,1,N);
original_distribution_mean=parameter1;
original_distribution_var=2*parameter1;
distrib_name='chi2';
end
x=x+random_vector;
number_of_variables=number_of_variables+1;
z=x/number_of_variables;
[n,axis_x]=hist(z,Nb_bins);
deltaX=axis_x(2)-axis_x(1);
pdf_estimate=n/(N*deltaX);
kurtosis_estimate=(mean((z-mean(z)).^4)./(var(z).^2))-3;
mean_estimate=original_distribution_mean;
var_estimate=original_distribution_var/number_of_variables;
[pdf_gaussian]=pdf('norm',axis_x,mean_estimate,sqrt(var_estimate));
plot(axis_x,pdf_estimate);
hold on;
plot(axis_x,pdf_gaussian,'r');
hold off;
ylim([0 max([pdf_estimate pdf_gaussian])+1]);
legend(sprintf('Sum of %d i.i.d variables z=(x1+...xn)/n',number_of_variables),'Gaussian pdf');
xlabel('random variable: z');
ylabel('Probability density fonction fZ(z)');
title(sprintf('Illustration of the Central Limit Theorem (%s distribution)',distrib_name));
fprintf('-> Sum of %d %s i.i.d variables: kurtosis=%f ',number_of_variables,distrib_name,kurtosis_estimate);
user_interface=input('Press q key to quit ?','s');
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.