What is a Confidence Interval?

A confidence interval is a way to represent uncertainty. When an experiment is repeated, it produces different outcomes each time. Instead of reporting a single estimate, we report a range of plausible values.

A data scientist might say “We are 95% confident that the true mean waiting time is between 69 and 73 minutes.”

This means if we repeated the experiment over and over, and computed the interval over and over, 95% of these intervals would contain the true mean.

Calculating Confidence Intervals

For a population mean \(\mu\) with large sample conditions, the confidence interval is the margin of error of the mean: \[\bar{x} \pm z_{\alpha/2} \cdot \frac{\sigma}{\sqrt{n}}\] When \(\sigma\) is unknown, we use the \(t\) - distribution: \[\bar{x} \pm t_{\alpha/2, \, n-1} \cdot \frac{s}{\sqrt{n}}\] where: \(\bar{x}\) is the sample mean, \(s\) is the sample standard deviation, \(n\) is the sample size, \(t_{\alpha/2, \, n-1}\) is the critical value from the \(t\) - distribution

Determining the Width of the Interval

We use this formula to calculate the margin of error: \[E = t_{\alpha/2, \, n-1} \cdot \frac{s}{\sqrt{n}}\] The margin of error determines how wide the interval is:

\[E = t_{\alpha/2, \, n-1} \cdot \frac{s}{\sqrt{n}}\]

Factors that affect the interval:

  • Large sample size (\(n\)) (narrower)
  • Lower confidence level (narrower)
  • More variability in the data (wider)
  • Higher confidence level (wider)

The Dataset: Old Faithful

This dataset records the eruptions of Old Faithful, the famous geyser in Yellowstone National Park

   eruptions        waiting    
 Min.   :1.600   Min.   :43.0  
 1st Qu.:2.163   1st Qu.:58.0  
 Median :4.000   Median :76.0  
 Mean   :3.488   Mean   :70.9  
 3rd Qu.:4.454   3rd Qu.:82.0  
 Max.   :5.100   Max.   :96.0  

What is the average waiting time between eruptions?

To answer this question we will demonstrate the confidence interval.

Distribution of Waiting Times

The dataset plots a bimodal distribution (it has two peaks). The mean eruption time is represented by the vertical dashed line.

Using Code to Compute the Interval

Using R, we run the t.test() function to compute the confidence interval.

t_result <- t.test(faithful$waiting, conf.level = 0.95)

t_result$conf.int
t_result$estimate
  • $conf.int extracts the interval width limits
  • $estimate extracts the mean

Code Output

  • Sample mean: 70.9 minutes
  • 95% Confidence Interval: (69.27, 72.52)

The sample mean is the estimated mean. The confidence interval represents the probable range of the true mean with a 95% confidence level.

Visualizing the Confidence Interval

The higher the confidence, the wider the interval of the true value.

How Sample Size Affects Interval Size

Visualizing Interval Dynamics

Key Takeaways

  • The data shows that Old Faithful has a mean eruption time of 70.9 minutes and a 95% confidence interval of 69 to 73 minutes.
  • Higher confidence for the true value increases the width of the confidence interval
  • A larger sample size reduces the width of the confidence interval
  • To communicate uncertainty, give an estimated value, and then a confidence interval that represents the probable range of the true value.

Confidence Interval formula: \[\bar{x} \pm t_{\alpha/2, \, n-1} \cdot \frac{s}{\sqrt{n}}\]