MATLAB: Calculate confidence interval for gamma function

confidence intervalgamrnd

Hi!
I am supposed to compute the confidence intervals for a gamma distributed sample (samplesize n=5, mean value mu=1, standard deviation=2 and alfa=1, beta=1) and repeat the simulation 10 000 times with a for-loop. The goal is to compute how many of the confidence intervals that contains the true mean value when the sample size is 5 and compare it to a samplesize of 100.
When using the following code I get that all of the confidence intervals contains the mean value when n=100 and that 97,45% of the intervals contain the mean value when n=5 which is too large. The answer is supposed to be less than 95% when n=5 and about 95% when n=100. When calculating the CI I should assume normal distribution?
Can anyone see what I am doing wrong?
Thank you!
clc
clear
a=1;
b=1;
n = 5; % samplesize
nu = n – 1; % degrees of freedom
conf = 0.95; %konfidensgraden är 0.95
alpha = 1 – conf;
pLo = alpha/2; %lower limit
pUp = 1 – alpha/2; %upper limit
number=0; % number of samples containing the true mean value before the loop
for i=1:10000
g = gamrnd(a,b,n,1);
gmean = mean(g); % calculated mean value
se = std(g); % calculated standard deviation
crit = tinv([pLo pUp], nu); %
ci = gmean + crit*se % calculating the confidence interval
if ci(1)<1<ci(2) % checking if the true mean value (1) is withing the CI
number=number+1 %number of times the mean value is within the CI
end
end
proportion=number/10000

Best Answer

I am not certain what you are permitted to use. I would use fitdist then paramci. With respect to assuming a distribution of the means, consider the Central Limit Theorem.