In this answer I aim to describe the difference between confidence intervals and credible intervals in an intuitive way.
I hope that this may help to understand:
- why/how credible intervals are better than confidence intervals.
- on which conditions the credible interval depends and when they are not always better.
Credible intervals and confidence intervals are constructed in different ways and can be different
see also: The basic logic of constructing a confidence interval and If a credible interval has a flat prior, is a 95% confidence interval equal to a 95% credible interval?
In the question by probabilityislogic an example is given from Larry Wasserman, which was mentioned in the comments by suncoolsu.
$$X \sim N(\theta,1) \quad \text{where} \quad \theta \sim N(0,\tau^2)$$
We could see each experiment with random values for $\theta$ and $X$ as a joint variable. This is plotted below for the 20k simulated cases when $\tau=1$
This experiment can be considered as a joint random variable where both the observation $X$ and the underlying unobserved parameter $\theta$ have a multivariate normal distribution.
$$f(x,\theta) = \frac{1}{2 \pi \tau} e^{-\frac{1}{2} \left((x-\theta)^2+ \frac{1}{\tau^2}\theta^2\right)}$$
Both the $\alpha \%$-confidence interval and $\alpha \%$-credible interval draw boundaries in such a way that $\alpha \%$ of the mass of the density $f(\theta,X)$ falls inside the boundaries. How do they differ?
The credible interval draws boundaries by evaluating the $\alpha \%$ mass in a horizontal direction such that for every fixed $X$ an $\alpha \%$ of the mass falls in between the boundaries for the conditional density $$\theta_X \sim N(cX,c) \quad \text{with} \quad c=\frac{\tau^2}{\tau^2+1}$$ falls in between the boundaries.
The confidence interval draws boundaries by evaluating the $\alpha \%$ mass in a vertical direction such that for every fixed $\theta$ an $\alpha \%$ of the mass falls in between the boundaries for the conditional density $$X_\theta \sim N(\theta,1) \hphantom{ \quad \text{with} \quad c=\frac{\tau^2}{\tau^2+1}}$$
What is different?
The confidence interval is restricted in the way that it draws the boundaries. The confidence interval places these boundaries by considering the conditional distribution $X_\theta$ and will cover $\alpha \%$ independent from what the true value of $\theta$ is (this independence is both the strength and weakness of the confidence interval).
The credible interval makes an improvement by including information about the marginal distribution of $\theta$ and in this way it will be able to make smaller intervals without giving up on the average coverage which is still $\alpha \%$. (But it becomes less reliable/fails when the additional assumption, about the prior, is not true)
In the example the credible interval is smaller by a factor $c = \frac{\tau^2}{\tau^2+1}$ and the improvement of the coverage, albeit the smaller intervals, is achieved by shifting the intervals a bit towards $\theta = 0$, which has a larger probability of occurring (which is where the prior density concentrates).
Conclusion
We can say that*, if the assumptions are true then for a given observation $X$, the credible interval will always perform better (or at least the same). But yes, the exception is the disadvantage of the credible interval (and the advantage of the confidence interval) that the conditional cover probability $\alpha \%$ is biased depending on the true value of the parameter $\theta$. This is especially detrimental when the assumptions about the prior distribution of $\theta$ are not trustworthy.
*see also the two methods in this question The basic logic of constructing a confidence interval. In the image of my answer it is illustrated that the confidence interval can place the boundaries, with respect to the posterior distribution for a given observation $X$, at different 'heights'. So it may not always be optimally selecting the shortest interval, and for each observation $X$ it may be possible to decrease the length of the interval by shifting the boundaries while enclosing the same $\alpha \%$ amount of probability mass.
For a given underlying parameter $\theta$ the roles are reversed and it is the confidence interval that performs better (smaller interval in vertical direction) than the credible interval. (although this is not the performance that we seek because we are interested in the intervals in the other direction, intervals of $\theta$ given $X$ and not intervals of $X$ given $\theta$)
About the exception
Examples based on incorrect prior assumptions are not acceptable
This exclusion of incorrect assumptions makes it a bit a loaded question. Yes, given certain conditions, the credible interval is better than the confidence interval. But are those conditions practical?
Both credible intervals and confidence intervals make statements about some probability, like $\alpha \%$ of the cases the parameter is correctly estimated. However, that "probability" is only a probability in the mathematical sense and relates to the specific case that the underlying assumptions of the model are very trustworthy.
If the assumptions are uncertain then this uncertainty should propagate into the computed uncertainty/probability $\alpha \%$. So credible intervals and confidence intervals are in practice only appropriate when the assumptions are sufficiently trustworthy such that the propagation of errors can be neglected. Credible intervals might be in some cases easier to compute, but the additional assumptions, makes credible intervals (in some way) more difficult to apply than confidence intervals, because more assumptions are being made and this will influence the 'true' value of $\alpha \%$.
Additional:
This question relates a bit to Why does a 95% Confidence Interval (CI) not imply a 95% chance of containing the mean?
See in the image below the expression of conditional probability/chance of containing the parameter for this particular example
The $\alpha \%$ confidence interval will correctly estimate/contain the true parameter $\alpha \%$ of the time, for a each parameter $\theta$. But for a given observation $X$ the $\alpha \%$ confidence interval will not estimate/contain the true parameter $\alpha \%$ of the time. (type I errors will occur at the same rate $\alpha \%$ for different values of the underlying parameter $\theta$. But for different observations $X$ the type I error rate will be different. For some observations the confidence interval may be more/less often wrong than for other observations).
The $\alpha \%$ credible interval will correctly estimate/contain the true parameter $\alpha \%$ of the time, for each observation $X$. But for a given parameter $\theta$ the $\alpha \%$ credible interval will not estimate/contain the true parameter $\alpha \%$ of the time. (type I errors will occur at the same rate $\alpha \%$ for different values of the observed parameter $X$. But for different underlying parameters $\theta$ the type I error rate will be different. For some underlying parameters the credible interval may be more/less often wrong than for other underlying parameters).
Code for computing both images:
# parameters
set.seed(1)
n <- 2*10^4
perc = 0.95
za <- qnorm(0.5+perc/2,0,1)
# model
tau <- 1
theta <- rnorm(n,0,tau)
X <- rnorm(n,theta,1)
# plot scatterdiagram of distribution
plot(theta,X, xlab=expression(theta), ylab = "observed X",
pch=21,col=rgb(0,0,0,0.05),bg=rgb(0,0,0,0.05),cex=0.25,
xlim = c(-5,5),ylim=c(-5,5)
)
# confidence interval
t <- seq(-6,6,0.01)
lines(t,t-za*1,col=2)
lines(t,t+za*1,col=2)
# credible interval
obsX <- seq(-6,6,0.01)
lines(obsX*tau^2/(tau^2+1)+za*sqrt(tau^2/(tau^2+1)),obsX,col=3)
lines(obsX*tau^2/(tau^2+1)-za*sqrt(tau^2/(tau^2+1)),obsX,col=3)
# adding contours for joint density
conX <- seq(-5,5,0.1)
conT <- seq(-5,5,0.1)
ln <- length(conX)
z <- matrix(rep(0,ln^2),ln)
for (i in 1:ln) {
for (j in 1:ln) {
z[i,j] <- dnorm(conT[i],0,tau)*dnorm(conX[j],conT[i],1)
}
}
contour(conT,conX,-log(z), add=TRUE, levels = 1:10 )
legend(-5,5,c("confidence interval","credible interval","log joint density"), lty=1, col=c(2,3,1), lwd=c(1,1,0.5),cex=0.7)
title(expression(atop("scatterplot and contourplot of",
paste("X ~ N(",theta,",1) and ",theta," ~ N(0,",tau^2,")"))))
# expression succes rate as function of X and theta
# Why does a 95% Confidence Interval (CI) not imply a 95% chance of containing the mean?
layout(matrix(c(1:2),1))
par(mar=c(4,4,2,2),mgp=c(2.5,1,0))
pX <- seq(-5,5,0.1)
pt <- seq(-5,5,0.1)
cc <- tau^2/(tau^2+1)
plot(-10,-10, xlim=c(-5,5),ylim = c(0,1),
xlab = expression(theta), ylab = "chance of containing the parameter")
lines(pt,pnorm(pt/cc+za/sqrt(cc),pt,1)-pnorm(pt/cc-za/sqrt(cc),pt,1),col=3)
lines(pt,pnorm(pt+za,pt,1)-pnorm(pt-za,pt,1),col=2)
title(expression(paste("for different values ", theta)))
legend(-3.8,0.15,
c("confidence interval","credible interval"),
lty=1, col=c(2,3),cex=0.7, box.col="white")
plot(-10,-10, xlim=c(-5,5),ylim = c(0,1),
xlab = expression(X), ylab = "chance of containing the parameter")
lines(pX,pnorm(pX*cc+za*sqrt(cc),pX*cc,sqrt(cc))-pnorm(pX*cc-za*sqrt(cc),pX*cc,sqrt(cc)),col=3)
lines(pX,pnorm(pX+za,pX*cc,sqrt(cc))-pnorm(pX-za,pX*cc,sqrt(cc)),col=2)
title(expression(paste("for different values ", X)))
text(0,0.3,
c("95% Confidence Interval\ndoes not imply\n95% chance of containing the parameter"),
cex= 0.7,pos=1)
library(shape)
Arrows(-3,0.3,-3.9,0.38,arr.length=0.2)