Confidence Interval Algorithm

635 Views Asked by At

I am trying to write a C++ program for parameter estimation(with Confidence Interval information) of an Exponentially distributed data set. I understand that $\lambda \bar{X} \sim \Gamma(n, n)$. To come up with numeric values of lower/higher confidence intervals for a specified $\alpha$, I need to be able to compute Inverse Gamma. Could you please point me to some algorithms?

1

There are 1 best solutions below

1
On

Either I misunderstand the problem, or you are making it more difficult than necessary.

Let $L$ and $U$ cut probability $\alpha/2$ from the lower and upper tails of $Gamma(shape=n,rate=n),$ Then a $1 - \alpha$ confidence interval for $\lambda$ is found as follows: $$P(L < \lambda \bar X < U) = P(L/\bar X < \lambda < U/\bar X) = 1-\alpha,$$ so the desired CI is $(L/\bar X,\; U/\bar X)$.

It is not difficult to program numerical integration to find $U$ and $L$ because the PDF of $Gamma(n,n)$ can be evaluated. Alternatively, I'm sure there must be a compiled FORTRAN program in the IMSL library of statistical algorithms that can be called from C++.

In particular, if $X_1, X_2, \dots, X_{25}$ is a random sample from $Exp(rate = .2),$ we might have the following sample (rounded to 3 places):

  1.515  0.187  6.270  3.291  3.597 10.680  1.572 22.555  4.924  0.063
  0.214  0.465 19.042  2.467  4.663  2.101  7.597 10.053  0.017  5.627
 12.124  7.579  0.735 11.290  4.153

The sample mean is $\bar X = 5.711.$ The cut-off points for a 95% CI from R are

 qgamma(c(.025,.975), 25, 25)
 ## 0.6471473 1.4284039

so that the 95% CI is

 qgamma(c(.025,.975), 25, 25)/mean(x)
 ## 0.1133112 0.2501040

The (slightly biased) maximum likelihood estimator of of $\lambda$ in this example is $\hat \lambda = 1/\bar X = 0.175,$ which is contained in the CI, but not exactly at the center of it, owing to the skewness of the distributions involved.

The Wikipedia article on 'exponential distribution' shows how to get essentially the same CI using printed tables of the chi-squared distribution. (The chi-squared distribution is a member of the gamma family of distributions, so an equivalent expression is feasible.)