Introduction to Confidence Intervals

What is a confidence interval?

Confidence is another term for probability in statistics. A confidence interval (CI) is the mean of your estimate plus and minus the variation in that estimate.

Mathematics of Confidence Intervals

The confidence interval for data which follows a standard normal distribution is:

\(CI = \bar{X} \pm \text{t*} \frac{\sigma}{\sqrt{n}}\)

Where:

  • \(CI\) = the confidence interval
  • \(\bar{X}\) = the population mean
  • \(\text{t*}\) = the critical value of the t distribution
  • \(\sigma\) = the population standard deviation
  • \(\sqrt{n}\) = the square root of the population size

Mathematics of Confidence Intervals

In reality, the population values are usually unknown, so the population values need to be replaced with sample values. As a result, the formula is changed to:

\(CI = \hat{x} \pm \text{t*} \frac{s}{\sqrt{n}}\)

Where:

  • \(\hat{x}\) = the sample mean
  • \(s\) = the sample standard deviation

The USAccDeaths Dataset

deaths_df <- tibble (
  date = seq(from = as.Date("1973-01-01"),
             to = as.Date("1978-12-01"),
             by = "month"),
  deaths = as.vector(USAccDeaths)
  )
deaths_summary <- summary(USAccDeaths)
  • Time period: January 1973 to December 1978
  • Observations: 72 months
  • Minimum: 6892 deaths
  • Maximum: 1.1317^{4} deaths
  • Mean: 8789

Goal: Estimate the pop. mean monthly accidental deaths with a 95% CI.

Time Series Visualization

Seasonal Analysis

Interactive 3D Visualization

R Code for Confidence Interval Calculation

alpha <- 0.05  # 1-alpha = 95% confidence
n <- length(USAccDeaths)
sample_mean <- mean(USAccDeaths)
sample_sd <- sd(USAccDeaths)

# Calc margin of error using t-dist
margin_error <- qt(1-alpha/2, df=n-1) * sample_sd/sqrt(n)

# Calc confidence interval
lower_ci <- sample_mean - margin_error
upper_ci <- sample_mean + margin_error
  • Sample mean: 8789 deaths per month
  • 95% Confidence Interval: [8564, 9014]