2023-04-14

Definition

A range of estimates of an unknown parameter

Overview

  • What is a Confidence Interval
  • Calculating Confidence Intervals
  • Confidence Intervals for the Mean of Normally Distributed Data
  • Confidence Intervals for Proportions
  • Confidence Intervals for Non-normally Distributed Data
  • Critical Values

What is a Confidence Interval

  • The mean of your estimate plus and minus the variation in that estimate
  • Desired confidence level is one minus the alpha value

Calculating Confidence Intervals

  • Know point estimate you are constructing the confidence interval for
  • Finding the standard deviation:
    1. Find the sample variance
    • \(s^2 = \frac{\sum_ (x - \overline{x})^2}{(N - 1)}\)
    1. Find the standard deviation
    • \(s = \sqrt{\frac{\sum_ (x - \overline{x})^2}{(n - 1)}}\)
  • Find critical value for test statistic
  • Use sample size

Confidence Intervals for the Mean of Normally Distributed Data

  • Find the critical value 95% confidence interval:
    • z_star_95 <- qnorm(0.975) z_star_95
  • Calculate the confidence interval:
    • \(CI = \overline{x} \pm z\frac{s}{\sqrt{n}}\)
    • samp %>% summarise(lower = mean(area) - z_star_95 * (sd(area) / sqrt(n)), upper = mean(area) + z_star_95 * (sd(area) / sqrt(n)))

Confidence Intervals for Proportions

  • Same pattern as CI for means, use sample proportion times one minus proportion in place of SD
  • \(\hat{p} \pm z * \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}\)
  • Example:
    • tab <- table(Chile$sex)
    • prop.test(tab, correct = FALSE)

Confidence Intervals for Non-normally Distributed Data

  • Two options:
    • find a distribution that matches the shape of your data and use that distribution to calculate the confidence interval
    • perform a transformation on your data to make it fit a normal distribution

Critical Values

  • Tell you how many standard deviations away from the mean you need to go to reach desired confidence level
  • Three Steps: Choose alpha value, Decide if you need one-tailed or two-tailed interval, Look up critical value that corresponds with the alpha value

Slide with R Code (for plot on next side)

set.seed(923874) #Create data data <- round(data.frame(x= 1:10, y = runif(10, 10, 20), lower = runif(10, 0, 10), upper = runif(10, 20, 30)), 2) install.packages(“ggplot2”) #Install & load ggpot library(“ggplot2”)

ggplot(data, aes(x, y)) + #ggplot2 with confidence intervals geom_point() + geom_errorbar(aes(ymin = lower, ymax = upper))

Example of C.I. (ggplot)

set.seed(923874)
data <- round(data.frame(x= 1:10,
                         y = runif(10, 10, 20),
                         lower = runif(10, 0, 10),
                         upper = runif(10, 20, 30)), 2)
ggplot(data, aes(x, y)) +
  geom_point() +
  geom_errorbar(aes(ymin = lower, ymax = upper))

Example of C.I. (Plotly Plot)

Example of C.I. (ggplot)

us_adults <- tibble(
  climate_change_affects = c(rep("Yes", 62000), rep("No", 38000))
)
ggplot(us_adults, aes(x = climate_change_affects)) +
  geom_bar(fill = 'blue') +
  labs(
    x = "", y = "",
    title = "Do you think climate change is affecting your local community?"
  ) +
  coord_flip()