Given a vector of numbers sampled from the normal distribution, how do I estimate the parameters (i.e. the mean and variance) of the normal distribution from which those numbers were sampled?
The Matlab function you are looking for is normfit
. If you call normfit
with only one argument X
, it will give you 2 outputs, an estimate of the mean and of the standard deviation:
[muhat,sigmahat] = normfit(X)
where the muhat
is the estimate of mean and sigmahat
the estimate of the standard deviation.
Now if you call it with a second argument alpha
it will give 4 outputs, the 2 estimates, and also the confidence intervals for each estimate:
[muhat,sigmahat,muci,sigmaci] = normfit(X,alpha)
muci
contains are the confidence interval on the mean and sigmaci
the confidence interval on the standard deviation.
Example:
>>a=randn(1,100);
>>[muhat,sigmahat,muci,sigmaci] = normfit(a,.01);
>>sigmaci
sigmaci =
0.8550
1.2360
So P(0.8550< sigma
< 1.2360) = 1-0.1.
sigma_2
is the variance so by simply squaring sigmaci
you have the confidence interval on sigma_2
:
>>sigma_2ci=sigmaci.^2
sigma_2ci =
0.7310 1.5277
and P(0.7310< sigma_2
< 1.5277) = 1-0.1.