Constructing confidence intervals

This online calculator constructs confidence intervals for four cases: for estimating the mean with unknown parameter values, for estimating variance with unknown parameter values, for estimating the mean with known variance, and for estimating variance with known mean.

Formulas and some theory can be found below the calculator.

PLANETCALC, Confidence intervals

Confidence intervals

Numbers may be separated by commas, semicolons, spaces, or newlines. Use a decimal point as the decimal separator.
A priori specified mean value.
Refer specifically to variance, not standard deviation
An integer of at least 2.
Variance calculated using division by n − 1.
Point estimate
 
Lower bound
 
Upper bound
 
Interval length
 
Sample size
 
Degrees of freedom
 
Distribution
 
Lower quantile
 
Upper quantile
 
Digits after the decimal point: 6

Methods for constructing confidence intervals under the condition that the source data are normal

No. What we estimate What is known Statistic used Distribution Confidence interval
1 Variance \sigma^2 Mean \mu is known \frac{\sum_{i=1}^n (x_i - \mu)^2}{\sigma^2} \chi^2(n) \left[ \frac{\sum_{i=1}^n (x_i - \mu)^2}{h^{(n)}_{(1+\alpha)/2}};\; \frac{\sum_{i=1}^n (x_i - \mu)^2}{h^{(n)}_{(1-\alpha)/2}} \right]
2 Mean \mu Variance \sigma^2 is known \frac{\bar{x} - \mu}{\sigma / \sqrt{n}} N(0,1) \bar{x} \pm z_{(1-\alpha)/2} \cdot \frac{\sigma}{\sqrt{n}}
3 Mean \mu Both unknown (estimating \mu) \frac{\bar{x} - \mu}{s / \sqrt{n}} T(n-1) \bar{x} \pm t_{(1-\alpha)/2}(n-1) \cdot \frac{s}{\sqrt{n}}
4 Variance \sigma^2 Both unknown (estimating \sigma^2) \frac{(n-1)s^2}{\sigma^2} = \frac{\sum_{i=1}^n (x_i - \bar{x})^2}{\sigma^2} \chi^2(n-1) \left[ \frac{(n-1)s^2}{h^{(n-1)}_{(1+\alpha)/2}};\; \frac{(n-1)s^2}{h^{(n-1)}_{(1-\alpha)/2}} \right]

Below I will explain where each thing comes from.

Method for constructing confidence intervals

In the general case (this is not the only method, but I did not look for others), confidence intervals can be constructed as follows1:

  1. Choose a confidence probability \alpha close to one.
  2. Choose some function depending on our sample and on the unknown parameter G(x_1, ..., x_n, \Theta), but such that, in turn, ITS distribution function does not depend on the unknown parameter \Theta:

F_G(t) \stackrel{\text{def}}{=} \mathbf{P}_\theta \{ G(x_1, \dots, x_n, \theta) \le t \}

  1. Choose two numbers \epsilon_1 > 0 and \epsilon_2 > 0 such that 1-\alpha=\epsilon_1 + \epsilon_2. Next we are interested in values k_1 and k_2 such that

F_G(\kappa_1) \le \varepsilon_1, \quad F_G(\kappa_2) \ge 1 - \varepsilon_2

Whence

\mathbf{P}_\theta \{ \kappa_1 < G(x_1, \dots, x_n, \theta) \le \kappa_2 \} \ge 1 - \varepsilon_2 - \varepsilon_1 = \alpha,

Since we chose G such that its distribution function does not depend on \Theta, then k_1 and k_2 also do not depend on \Theta.

  1. Move to the double inequality

\kappa_1 < G(x_1, \dots, x_n, \theta) \le \kappa_2

and solve it for \Theta. The values will depend on the sample. If the solution is denoted by \beta, then we can write

\mathbf{P}_\theta \{ \theta \in ( \beta_1(x_1, \dots, x_n), \beta_2(x_1, \dots, x_n)) \} \ge \alpha

The computed values will be the confidence interval. I.e. an interval into which the true value of the unknown quantity falls with a given probability.

Actually, everything further has already been calculated before us - for the above cases, functions with known distributions have already been selected that allow confidence intervals to be calculated. Along the way, new distributions had to be introduced and theorems proved, but this is rather difficult. Students and engineers need only know that it is so, and the conditions of application. Below we consider each case separately.

Constructing a confidence interval for the mean with known variance

Let us start with the simplest case to explain - constructing a confidence interval for the mean with known variance. How can the variance of a random variable be known, you ask. However, this is a fairly common case in practice, since variance, or spread, most often characterizes the physical properties of an instrument or technological process. A classic example: the error of an instrument, indicated in its passport as the standard deviation. We do not know the true value of the measured quantity, but we do know the "noise" of the instrument. We make a series of measurements and construct a confidence interval for the mean value using the standard deviation.

The clever function G for this case was chosen as follows

G(x_1, \dots, x_n; \mu) = \frac{x_1 + \dots + x_n - n\mu}{\sigma \sqrt{n}}

Here the theorem is used that the sum of an arbitrary number of independent normal random variables has a normal distribution. In this case the function G has the standard normal distribution N(0,1). We can write the double inequality using quantiles

z_{(1-\alpha)/2} < \frac{x_1 + \dots + x_n - n\mu}{\sigma \sqrt{n}} < z_{(1+\alpha)/2}

Whence

\bar{x} - \frac{\sigma z_{(1+\alpha)/2}}{\sqrt{n}} < \mu < \bar{x} - \frac{\sigma z_{(1-\alpha)/2}}{\sqrt{n}}.

Or, due to the symmetry of the normal distribution

\bar{x} - \frac{\sigma}{\sqrt{n}} z_{(1+\alpha)/2} < \mu < \bar{x} + \frac{\sigma}{\sqrt{n}} z_{(1+\alpha)/2}

Constructing a confidence interval for the mean with unknown variance

Now let us consider constructing a confidence interval for the mean value of some random variable when we know neither its true mean value nor its true variance. This is the most frequent case when you obtain a series of measurements of something - most often you know nothing at all.

For example, you want to check how a new fertilizer affects the tomato harvest.
You planted 30 beds, applied fertilizer, and measured the resulting yield in kilograms. The true mean is the potential yield of the variety with fertilizer applied, if it were planted everywhere under ideal average conditions. It is unknown. The true variance in this case is the responsiveness to microclimate and errors in watering / fertilizer application. One bed is located in a lowland (more moisture), another on a hill (drier), and so on. How strongly does yield change from bed to bed? That is also unknown.

Here the choice of the clever function G is determined by Fisher's theorem. Here is its formulation from Wikipedia2:

Let X_1,\ldots,X_n \sim \mathrm{N}(\mu,\sigma^2) be an independent sample from a normal distribution. Let \overline{X} be the sample mean, and S^2 the sample variance. Then

  • The random variables \overline{X} and S^2 are independent;
  • The random variable  \sqrt{n} \cdot \frac{\overline{X} - \mu}{\sigma} \sim \mathrm{N}(0,1) \sim Z has a standard normal distribution
  • The random variable \frac{(n-1)\cdot S^2}{\sigma^2} = \frac{1}{\sigma^2} \sum_{i=1}^{n} (X_i - \bar{X})^2 \sim \chi^2_{n-1} has a chi-square distribution with n-1 degrees of freedom.

And from the standard normal distribution and the chi-square distribution one can assemble the Student distribution by the following formula

T = \frac{Z}{\sqrt{\chi^2_k/k}}, where k is the number of degrees of freedom.

So let us construct our function G by dividing one by the root of the other divided by n-1:

G(x_1, \dots, x_n; \mu, \sigma^2) = \frac{(\sqrt{n}(\bar{x} - \mu))/\sigma}{\sqrt{\frac{1}{n-1} \frac{1}{\sigma^2} \sum_{i=1}^{n} (x_i - \bar{x})^2}}

We know that this function has the Student distribution with n-1 degrees of freedom, plus, luckily, the unknown parameter \sigma can be canceled in it

Thus

G(x_1, \dots, x_n; \mu, \sigma^2) = \frac{\sqrt{n}(\bar{x} - \mu)}{s} \sim T(n-1)

And then, denoting the quantiles of the Student distribution by t and expressing \mu, we obtain the confidence interval formula.

\bar{x} - \frac{s}{\sqrt{n}} t^{(n-1)}_{(1+\alpha)/2} < \mu < \bar{x} + \frac{s}{\sqrt{n}} t^{(n-1)}_{(1+\alpha)/2}

Since the Student distribution is symmetric, here it is also enough to substitute only one quantile value into the formula, as in the previous case.

Constructing a confidence interval for variance with known mean

We have dealt with estimating means, but it seems we also need to estimate variance. And the first case is constructing a confidence interval for variance with a known true mean. Again, where in real life are there tasks where the true mean is known and variance is needed? The first option is problems inverse to the problem of estimating the mean with known variance, namely, calibration of an instrument. That is, start placing a reference 1-kilogram weight on the scales and see what they show, estimate the spread of values shown by the scales (putting the weight not once, obviously). Besides, the mean can be fixed in hypothesis testing (they look at what the spread will be if the mean is like this).

We construct the function G as follows:

G(x_1, \dots, x_n; \sigma^2) = \frac{\sum_{i=1}^n (x_i - \mu_0)^2}{\sigma^2} = \sum_{i=1}^n \left( \frac{x_i - \mu_0}{\sigma} \right)^2.

Here everything is simple - this is literally the chi-square distribution with n degrees of freedom, and it does not depend on \sigma.

Denoting the quantiles of the chi-square distribution by h and expressing \sigma, we obtain the confidence interval formula.

\frac{\sum_{i=1}^n (x_i - \mu_0)^2}{h_{(1+\alpha)/2}^{(n)}} < \sigma^2 < \frac{\sum_{i=1}^n (x_i - \mu_0)^2}{h_{(1-\alpha)/2}^{(n)}}

The chi-square distribution is asymmetric, so both quantiles have to be taken.

Constructing a confidence interval for variance with unknown mean

Why is this needed? For the same reason as in the previous case. We want to estimate the variability, the "tightness" or "stability" of a process, only the true mean is unknown to us.

For this case the following function G was constructed:

G(x_1, \dots, x_n; \mu, \sigma^2) = \frac{\sum_{i=1}^n (x_i - \bar{x})^2}{\sigma^2}

The "catch" here is that the unknown value \mu does not participate in the function at all. And by Fisher's theorem we know that this function has a chi-square distribution with n-1 degrees of freedom. Then we do the same as in the previous case and obtain the confidence interval formula:

\frac{(n - 1)s^2}{h_{(1+\alpha)/2}^{(n-1)}} < \sigma^2 < \frac{(n - 1)s^2}{h_{(1-\alpha)/2}^{(n-1)}}

Applicability criteria

Let us repeat once more - all formulas listed above in the table (using quantiles of the normal distribution, Student distribution, and chi-square distribution) are exact only in one single case: the original random variable must be distributed strictly according to the normal law (Gauss).

If the distribution is not normal, then when estimating the mean with a large sample size we are lucky - thanks to the Central Limit Theorem (CLT), as the sample size grows the sample mean always tends to a normal distribution, regardless of what distribution the original data had (exponential, uniform, binomial, etc.). The traditional boundary between a small and a large sample in statistics is 30. Sometimes people speak of a sample of size 50 - 100, but much here depends on the asymmetry of the distribution or the heaviness of its "tails".

Conclusion - when estimating the mean for large samples, the distribution can be ignored (thanks to the CLT). For small samples from a NON-normal distribution (for example, binomial or lognormal), Student criteria give an error — nonparametric methods must be used (for example, the Wilcoxon test).

For variance, everything is bad. The chi-square distribution is extremely sensitive to deviations from normality, and for non-normal distributions other approaches must be used.


  1. Manita A. D. Probability Theory and Mathematical Statistics: Textbook. -- Moscow: Publishing Department of UNTs DO, 2001. -- 120 p. TeorVer-Online ↩

  2. Fisher's theorem for normal samples ↩

URL copied to clipboard
PLANETCALC, Constructing confidence intervals

Comments