Confidence interval with normfit/fitdist/paramci differ from manual calculation depending on the number of elements. Why??

11 views (last 30 days)
I am testing some confidence interval calculation, however, I have noticed differences using the Matlab functions normfit/fitdist/paramci from the manual calculation. Please have a look to the code below, and test the data with more elements. As the data size increases the differences are smaller. Does someone have a clue/solution/explanation?
%%Cleaning service
clear all; close all;
%%Data and processing
conf = norminv([0.025 0.975],0,1); % for 95%
data = normrnd(0.158,0.0265,10,1); % Change the third argument to 100, 1000, 1000, ...
[mu,sigma,muci,sigmaci] = normfit(data,.05); % for 95%
pd = fitdist(data,'Normal'); ci = paramci(pd,'Alpha',.05); % for 95%
xplus = mu + conf(2)*sigma*(1/sqrt(length(data)));
xminus = mu - conf(2)*sigma*(1/sqrt(length(data)));
Difference = [ci(1,1)-xminus ci(2,1)-xplus]

Answers (1)

Francesco Burroni
Francesco Burroni on 13 Feb 2022
I also encountered the same problem.
It seems to me that MATLAB is using a t-distribution (with n-1 degrees of freedom, where n is the sample length) to determine the lower and upper bounds of the 95% CI. I get an exact match when using tinv() instead of norminv in your formula.
Hence, it also makes sense that that the CI converge as sample size increases, because the t-distribution approximates a normal one as the df increase.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!