2023-03-10

The Definition of a Confidence Interval

  • A confidence interval is an estimated range for where we expect to find a particular parameter.
  • Essentially, this is a range where we are somewhat certain the actual value lies in.

Different Types of Confidence Intervals

  • There are a number of different types of confidence intervals, to include:
  • Population Mean
  • Ratio of 2 Variances
  • Variance
  • Binomial proportion
  • Slope of a Regression Model

The CI Formula and its Variables

  • The following is the formula used in order to calculate a confidence interval: \[\begin{equation} CI = \bar{x} \pm Z \cdot \frac{s}{\sqrt{n}} \end{equation}\]

  • Now, as for the variables, x represents our sample mean, z is the z-value for our confidence level, s is the sample standard deviation, and n is the sample size.

The 95% Confidence Interval Graphically

Breaking it down: the CI Process

  • 1)Find n (# of samples)
  • 2)Find your mean
  • 3)Find your standard deviation(s)
  • 4)Select the CI
  • 5)Find z for the given CI
  • 6)Plug into the CI formula
  • 7)Conclude and interpret

Basic Example of Finding CI

Ex: Find the 95% CI given the following: \[n = 75, x = 20, s = 5.4\] Sol: \[CI = 20 \pm \frac{5.4}{\sqrt{20}}\] \[= 21.21\] \[=18.79\] Thus, \[CI = (18.79, 21.21)\]

Application of CI: The Interval Plot

  • How are these intervals useful? We can represent these intervals visually through an interval plot. This is a plot used to show the confidence intervals for the mean of a set of data points.
  • Why is an interval plot useful? If you ever need to compare different groups in your data, an interval plot is a stellar tool to use.

Example of an Interval Plot

Bar Plots with Confidence Intervals

R Code for Bar Plots with CIs

set.seed(813)
data <- list(rnorm(100, mean = 16, sd = 4),
             rnorm(100, mean = 14, sd = 3),
             rnorm(100, mean = 12, sd = 2.5))

mean <- sapply(data, mean)
se <- sapply(data, function(x) sd(x) / sqrt(length(x)))

par(mar = c(5, 4, 2, 1))

barplot(mean, ylim = c(0, 20), main = "Barplot with CIs",
        xlab = "Group Num", names.arg = c("1", "2", "3"),
        col = "pink", border = "black")

for (i in 1:3) {
  arrows(i, mean[i] + se[i], i, mean[i] - se[i], length = 0.1, angle = 90, code = 3, lwd = 2)
}