# Confidence Intervals

## Introduction&#x20;

A **confidence interval** is a range of values we are fairly certain the true value lies in.

Suppose we want to find the average height of women in the U.S. In order to find out what the average height of women in the U.S. is, we would have to go and measure the height of every woman in the U.S. and average this, data. It would be very impractical (and expensive!) to go out and measure the height of every woman in the U.S. But, we can find an answer by getting a random sample of women in the U.S. and find the average height of the women in this sample. However, because we have not measured the height of every woman, we cannot be 100% certain that the average height we find with our sample is the average height of all women in the U.S. We therefore find a "confidence interval". That is, a range of values the true value is likely in (an interval) and a certain level of confidence in this interval.

Let's think back to how this connects to the central limit theorem (CLT). The average height of the women from the random sample is the sample mean discussed in the last section. According to the CLT, the sample mean is distributed approximately normally; more so of course if the sample size is large. We are able to calculate a confidence interval specifically because of this knowledge that the sample mean is distributed approximately normally. This is one reason why the CLT is so important!

To continue the discussion of confidence intervals, we turn to a more concrete example. Suppose we measure the height of 200 randomly chosen women and get an average height of 5.35 feet and a standard deviation of 0.75 feet. The 95% confidence interval (which will be explained below) is 5.35 $$\pm$$ .1 feet. What this means is that the true average of the height of women in the U.S. (if we were to go and measure it) is likely to be between 5.25 and 5.45 feet. But, this interval might not include the true mean. The 95% means that if we repeat our experiment where we went out and measured the height of 200 randomly chosen women, 95% of these experiments will give us a confidence interval that includes the true mean. 5% will not include the true mean. There is a 5% chance our confidence interval does not include the true value.&#x20;

![](https://1640775911-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_QqIZ-ZgXL5GekACpb%2F-MV9Bxg5AzDUDJ458FiW%2F-MV9C1bXOntNS-NokQcG%2FCI1.png?alt=media\&token=23277c2b-be3a-4a30-86f1-14bee072c94b)

In the graphic above, each blue bar represents a confidence interval found as the result of an experiment. 19 out of 20 of the confidence intervals include the true value. 95% of the experiments include the true value. 1 experiment, or 5% of them do not include the true value.

{% hint style="info" %}
Note: There is a difference in saying that 95 out of 100 trials of confidence intervals contain the true value versus we are 95% sure that the true value is within the 95% confidence interval.
{% endhint %}

{% hint style="info" %}
By the definition of a confidence interval, which should be wider a 99% confidence interval or a 95%? Why? Are there any cases in which that is not true?\
\
Hint: Think of populations where all the parameters would be the same value.
{% endhint %}

## How to find a Confidence Interval

1. Find the number of elements in a sample $$n$$, find the sample mean$$\bar{X}$$, and find the sample standard deviation $$\bar{\sigma}$$.
2. &#x20;Decide what Confidence Interval we want. Then, find the "Z" value for that Confidence Interval:

| Confidence Interval | Z     |
| ------------------- | ----- |
| 80%                 | 1.282 |
| 85%                 | 1.440 |
| 90%                 | 1.645 |
| 95%                 | 1.960 |
| 99%                 | 2.576 |
| 99.5%               | 2.807 |
| 99.9%               | 3.291 |

3\.  Plug in these values to the Confidence Interval formula:

$$
\bar{X} \pm Z\frac{\bar{\sigma}}{\sqrt{n}}
$$

4\. The interval is then ( $$\bar{X} - Z\frac{\bar{\sigma}}{\sqrt{n}}, \bar{X} + Z\frac{\bar{\sigma}}{\sqrt{n}}$$ ).&#x20;

Note that as $$n$$, the number of samples used to calculate the sample mean, increases, the width of the confidence interval decreases. Also, as $$\bar{\sigma}$$ decreases, the width of the confidence interval decreases.

{% hint style="info" %}
Having a wider confidence interval is not always better. Think about if we had an 100% confidence interval from the minimum of the data to the maximum of it, we would be 100% sure that the data falls within the bounds, but it would not tell us anything we did not know before!
{% endhint %}

## Worked Example

Suppose we want to find the average age of people who go to see a new romantic comedy movie with 99% confidence. Thousands and thousands of people will go to see the movie, so we randomly choose just 87 movie-goers. We find $$n = 87, \bar{X} = 26.7, \bar{\sigma} = 4.6$$ . Since we want to know the average age with 99% confidence, we can look at the table and find $$Z = 2.576.$$ Plugging these values into our formula:

$$
\bar{X} \pm Z\frac{\bar{\sigma}}{\sqrt{n}} = 26.7 \pm \frac{2.759 \cdot 4.6}{\sqrt{87}} = 26.7 \pm 1.4
$$

So we are 99% confident that the average age of people who go to see the new romantic comedy movie is between 25.3 and 28.1 years.&#x20;

{% hint style="warning" %}
A 99% confidence interval between 25.3 and 28.1 does NOT mean that 99% of our population lies in that interval. As a sanity check, what does it mean? Is it possible that nearly everyone who watched a movie is within 3 years of each other?
{% endhint %}
