Predictive Hacks

Confidence vs Credible Intervals for Proportions

Confidence vs Credible

In Frequentist Statistics we communicate the Confidence Intervals where in Bayesian Statistics we communicate the Credible Intervals.

In this post we are not going to dive into formulas and theory. On contrary our goal is to give an example of how we can calculate the Confidence and the Credible Intervals using R and to see their differences.

The main difference is that according to Frequentists the Binomial distribution follows approximately the normal distribution \(N\sim(p,\frac{p(1-p)}{n})\) while according to Bayesians the conjugate prior is the beta distribution with shape parameters \(\alpha=Successes+1\) and \(\beta=Failures+1\)

Let’s consider the following example where the \(n=1000\), the \(p=20\%\) and we want to calculate the \(95\%\) Confidence and Credible Intervals.

# Probability 20%
# sample size n=1000
# alpha=5% since we want the 95% confidence and credible intervals

# 95% Confidence Interval
qnorm(c(alpha/2,(1-alpha/2)), mean=p, sd=sqrt((p*(1-p))/n))
0.1752082 0.2247918

Now we are going to calculate the Credible interval:

# 95% Credible Interval
qbeta(c(alpha/2,(1-alpha/2)), (n*p)+1, (n-n*p)+1)
0.1763924 0.2259372

As we can see the differences are quite small. Let’s see what are the density functions of the Normal and Beta of our example.


df1<-data.frame(Values = rnorm(1000, p, sqrt(p*(1-p)/n) ), Distribution="Normal")
df2<-data.frame(Values = rbeta(1000, (n*p)+1, (n-n*p)+1 ), Distribution="Beta")
ggplot(df, aes(x=Values, fill=Distribution))+geom_density(alpha=0.25)

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Leave a Comment

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s