As a final example in which a confidence interval can be obtained by inverting a hypothesis test, we will find a 95% confidence interval for the median of a data set from a random sample, without making any assumptions about the shape of the distribution from which the sample was selected.

Hypothesis test about the median

We find the confidence interval by considering a hypothesis test for the hypotheses

where the parameter \(\theta\) is the median of the distribution. Rather than using the \(n\) raw data values, we will base the test on the number of values less than \(\theta_0\). If \(\theta_0\) really is the median (and the null hypothesis is true), this will have a binomial distribution,

\[ Y \;\;=\;\; \text{number of values below }\theta_0 \;\;\sim\;\; \BinomDistn(n, \pi=0.5) \]

This can be used as a test statistic and the p-value for the test is the probability of \(Y\) being further from \(\diagfrac{n}{2}\) than was observed in the data.

We can apply trial-and-error to find the values of \(\theta_0\) that would result in the null hypothesis being accepted.

Example

A certain disease in dogs is characterized in the early stages by unusually high levels of a blood protein. This measurement has been proposed as a diagnostic test for infection: if the measured level is above a threshold value, the dog is diagnosed as having the disease. A ‘false positive’ occurs when a healthy dog happens to have a level above the threshold and is wrongly diagnosed as having the disease.

Measurements on a sample of 50 unaffected dogs gave the following results:

14.4
16.1
11.9
7.5
9.3
9.3
16.4
4.9
12.8
23.7
23.7
13.5
9.3
8.6
17.6
19.0
20.3
17.0
30.4
8.3
13.9
20.1
10.2
23.6
14.9
50.4
8.5
7.5
23.0
18.7
5.5
11.2
31.8
20.4
13.0
13.4
11.7
7.8
19.4
21.4
16.4
28.2
31.3
30.3
26.6

Measurements on a sample of 27 diseased dogs gave the results:

21.9
40.8
37.6
41.7
23.3
39.8
66.3
34.4
27.8
49.8
19.3
55.5
50.7
27.5
30.2
60.7
8.5
51.2
24.2
24.9
16.1
28.2
30.2
 
15.7
18.3
 
22.5
8.4
 

Find 95% confidence intervals for the median level of blood protein in the two groups.

For the 50 unaffected dogs, we would accept the null hypothesis that the median is \(\theta_0\) if the number of values less than \(\theta_0\), \(Y\), is not in the upper or lower 2.5% tails of the \(\BinomDistn(50, 0.5)\) distribution.

With a little trial-and-error, we would only reject H0 if \(y \le 17\) since

\[ P(Y \le 17) \;\;=\;\; 0.0164 \spaced{and} P(Y \le 18) \;\;=\;\; 0.0325 \]

and similarly we would reject H0 if \(y \ge 33\).

Values, \(y\), that would lead us to accepting the null hypothesis are therefore

\[ 18 \;\;\le\;\; y \;\;\le\;\; 32 \]

A 95% confidence interval for the median, \(\theta\), therefore consists of values such that between 18 and 32 data values are less — between the 18th and 32nd values in the data set when sorted into order. For the unaffected dogs, this results in a 95% confidence interval for the median,

\[ 13.4 \;\;\le\;\; \theta \;\;\le\;\; 19.0 \]

For the 27 diseased dogs, we would accept the null hypothesis that the median is \(\theta_0\) if the number of values less than it, \(y\), is between 8 and 19, so a 95% confidence interval for the median is between the 8th and 19th values in that data set when sorted into order,

\[ 22.5 \;\;\le\;\; \theta \;\;\le\;\; 39.8 \]

Illustration of the method for the 27 diseased dogs

The diagram below illustrates the procedure for the 27 diseased dogs.

The stacked dot plot at the bottom shows the data set. The diagram initially shows the steps for a two-tailed test for whether the median, \(\theta\), is 20.0.

  1. Of the \(n=27\) values in the data set, \(y=6\) are below 20.
  2. If the median was really 20.0, the number below it would have a \(\BinomDistn(n=27, \pi=0.5)\) distribution and this is shown in the bar chart at the top.
  3. The probability of getting as a "extreme" a value from this binomial distribution is twice the lower tail probability, 0.0059, and this is the p-value for the test.
  4. If testing at the 5% significance level, we would reject the null hypothesis H0: \(\theta = 20.0\).

Since the null hypothesis value \(\theta = 20.0\) is rejected by a test at 5% significance level, this value is not in a 95% confidence interval for \(\theta\).

Drag the slider to perform tests about whether \(\theta\) is other values. The values that result in accepting the null hypothesis (p-values over 0.05) are those that are in a 95% confidence interval,

\[ 22.5 \;\;\le\;\; \theta \;\;\le\;\; 39.8 \]