Credible Intervals versus Confidence Intervals
July 16, 2024
Suppose you have data
Note: Throughout this article, I use the convention that uppercase variables are random variables and lowercase variables are fixed (observed) quantities.
Confidence Intervals
This is the typical approach taught in any statistics class. However, its interpretation is nuanced.
We want to estimate
Hence,
And so the confidence interval is given by
Notice that
Credible Intervals
This is a Bayesian approach. We first set up a joint prior distribution for
If we integrate the last product with respect to
This looks similar to the confidence interval. But the difference is that we are calculating the probability of
- Take our original
normally-distributed sample points and compute the posterior probability distribution . - Draw a random sample of
points from the posterior , sort them, and use the 2.5% and 97.5% points to compute a posterior probability interval (credible interval). In other words, the original sample is used to specify the posterior distribution of and then a new sample is simulated from the posterior distribution of to compute the credible interval. This is why we can say there's a 95% probability lies in : and are the result of a simulation, and they should contain 95% of the values between them.
While the interpretation of credible intervals is easier to understand, there's no guarantee they will produce the same results as a confidence interval. That being said, they usually get pretty close. For our purposes, they are almost the same:
pop_mean <- 5.5
pop_sd <- 3
n <- 1000
set.seed(14151)
sample <- rnorm(n, mean = pop_mean, sd = pop_sd)
# Confidence interval
alpha <- 0.05
sample_mean <- mean(sample)
sample_sd <- sd(sample)
crit <- qt(alpha / 2, df = n - 1)
upper <- sample_mean + crit * sample_sd / sqrt(n)
lower <- sample_mean - crit * sample_sd / sqrt(n)
print(paste0(
upper,
", ",
lower
))
# Credible interval
set.seed(14560)
v = n - 1
simul <- rt(1000, df = v)
simul <- simul / sqrt(v / (v - 2))
simul <- simul * sample_sd / sqrt(n)
simul <- simul + sample_mean
interval <- sort(simul)[c(25, 976)]
print(interval)
For the confidence interval, we get
Conclusion
Ultimately, the distinction between the two is quite important. It's easy to think a 90% confidence interval has a 90% probability of containing the mean, but this is incorrect:
- A
% confidence interval for a parameter means that if we were to generate 100 (or 1000 or 10000) samples and compute the interval using some procedure like the one described above, then (or or ) of those intervals would cover the true population parameter. - A
% credible interval for a parameter means that there is a % chance that the interval computed from the posterior distribution of the parameter will contain the true population parameter.