- 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.
2023-03-10
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.
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)\]
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)
}