Search⌘ K
AI Features

Confidence Interval of Mean

Explore the process of calculating confidence intervals for the mean using both classical formulas and nonparametric bootstrap techniques in Python. Understand how to implement bootstrapping with functions, interpret 95% confidence levels, and compare bootstrapped intervals with conventional methods through visualization and practical coding.

SciPy is another very convenient library in the Python ecosystem for data science. It is a collection of mathematical algorithms and convenience functions built on NumPy. We can use stats.norm() from the library to accomplish this task of computing the confidence interval using the classical formula for means.

Classical approach

We have already inserted z-scores for the 95% confidence level in the formula above. Let's reconfirm the values of the z-score using the ppf module available in scipy.stats.norm(). We'll be using this to get percentiles for our confidence interval formula.

Python 3.8
from scipy import stats # import the library
# ppf() -- Percent point function (inverse of ``cdf`` -- cumulative distribution function)
print("So, the values of upper and lower z-scores for 95% confidence level are:",
stats.norm().ppf(q = 0.025),"&", stats.norm().ppf(q = 0.975)) # RV -- Random variable

Let's move on and compute the confidence interval using ...