How to calculate the confidence interval in both R and Python

Tracyrenee
Geek Culture
Published in
3 min readNov 6, 2022

--

In frequentist statistics, a confidence interval (CI) is a range of estimates for an unknown parameter. A CI is computed as a designated confidence level, with 95% confidence level being the most common. Factors affecting the width of the CI include the confidence level, sample size, and variability in the sample. With all other factors being the same, a larger sample would produce a narrower CI. a greater variability in the sample produces a wider CI, and a wider confidence level would demand a wider CI.

The formula for the confidence interval can be seen below:-

In this post I intend to calculate the confidence interval in both R and Python. I have written the code in R code in Replit, which is a free online interpreter/compiler. The Python code has been translated using Google Colab, which is a free online Jupyter Notebook hosted by Google.

I have taken the question that has been used in this post from a YouTube statistics course, which can be found…

--

--

Tracyrenee
Geek Culture

I have five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.