Inverting a test to find a confidence interval

There are two reasons why hypothesis tests may be simpler than confidence intervals:

In these situations, good approach to finding a confidence interval may be through hypothesis tests.

For example, the confidence intervals for a binomial proportion that we showed earlier were based on normal approximations to the number or proportion of successes. A hypothesis test about the probability of success can be performed using binomial probabilities without the need for this normal approximation.

A \((1 - \alpha)\) confidence interval for a parameter \(\theta\) can be found as follows:

  1. For different values of \(\theta_0\), perform a 2-tailed test for whether \(\theta = \theta_0\) at significance level \(\alpha\).
  2. A \((1 - \alpha)\) confidence interval for \(\theta\) consists of the values \(\theta_0\) that are not rejected by these tests.

This will be illustrated in an example.

Exact confidence interval for a binomial probability, \(\pi\)

We will now find a 95% confidence interval for the probability of success, \(\pi\), based on \(n=20\) binomial trials in which there were \(x=7\) successes.

The confidence interval can be based on a 2-tailed hypothesis test with null hypothesis H0: \(\pi = \pi_0\). For this test, we can use the test statistic \(X\) whose distribution is known when H0 is true,

\[ X \;\;\sim\;\; \BinomDistn(n=20, \pi_0) \]

For any value of \(\pi_0\), the p-value for the test can be found as double the smaller tail probability from this binomial distribution,

\[ 2 \times P(X \le 7 \mid \pi = \pi_0) \spaced{or} 2 \times P(X \ge 7 \mid \pi = \pi_0) \]

For a test at significance level \(\alpha = 5%\), we should reject the null hypothesis if the p-value is less than 0.05.


A 95% confidence interval for \(\pi\) can therefore be found as the values \(\pi_0\) that are not rejected in the above hypothesis test. By trial-and-error with different values of \(\pi_0\), we find the following p-values for testing whether \(\pi = 0.592\) and for testing \(\pi = 0.154\),

\[ 2 \times P(X \le 7 \mid \pi = 0.592) = 0.05 \spaced{and} 2 \times P(X \ge 7 \mid \pi = 0.154) = 0.05 \]

The null hypothesis is only accepted at the 5% significance level for values of \(\pi_0\) between these, so the exact 95% confidence interval is

\[ 0.154 \;\;\lt\;\; \pi \;\;\lt\;\; 0.592\]

The diagram below illustrates this. It shows the calculations to find the p-value for a two-tailed test of whether \(\pi = \pi_0\) based on this data set.

When the null hypothesis is true, the p-value is twice the smaller tail probability of the binomial distribution shown in this bar chart and is initially shown for testing whether \(\pi = 0.400\). This p-value is greater than 0.05 so we would accept the null hypothesis at the 5% significance level. This means that 0.400 is inside a 95% confidence interval for \(\pi\).

Drag the slider to find the p-values for testing whether \(\pi\) equals other values. (You can use the arrow keys on your keyboard for finer adjustment of \(\pi\).) Observe that: