Sunday , November 29 2026
Population vs sample, sampling methods, standard error, confidence intervals and the Central Limit Theorem with Python.

Inferential Statistics: Sampling, Confidence Intervals and CLT

Updated: 28 November 2026Level: IntermediateReading time: about 9 minutesNumPy · SciPy · tested

Inferential statistics uses a sample to draw conclusions about a whole population. We rarely measure everyone, so we estimate – and say how sure we are.

What You Will Learn

  • Population vs sample, parameter vs statistic
  • Sampling methods
  • Standard error
  • Confidence intervals in Python
  • The Central Limit Theorem, shown by simulation

Prerequisites

Statistical Distributions.

Key Ideas

Term Example
Population All 2 lakh students who took an exam
Sample 400 students we surveyed
Parameter The true average mark of all students (unknown)
Statistic The average mark of our sample (we calculate it)

Sampling Methods

Method How
Simple random Every member has an equal chance
Stratified Sample from each group (e.g. each state) in proportion
Cluster Randomly pick whole groups (e.g. schools)
Systematic Every k-th item from a list
Convenience Whoever is easy to reach – risky, often biased

Confidence Interval

Example
import numpy as np
from scipy import stats

rng = np.random.default_rng(1)
sample = rng.normal(loc=68, scale=12, size=40).round(1)   # marks of 40 students

mean, se = sample.mean(), stats.sem(sample)               # standard error = s / sqrt(n)
lo, hi = stats.t.interval(0.95, df=len(sample)-1, loc=mean, scale=se)
print("Sample mean:", round(mean, 2), " SE:", round(se, 2))
print("95% CI:", round(lo, 2), "to", round(hi, 2))
Output
Sample mean: 68.04  SE: 1.79
95% CI: 64.43 to 71.65

Explanation: We estimate the population mean is between about 64.4 and 71.7. “95% confidence” means: if we repeated the sampling many times, about 95% of such intervals would contain the true mean. We use the t-distribution because the population standard deviation is unknown. A bigger sample gives a smaller standard error and a narrower interval.

Central Limit Theorem

Example
pop = rng.exponential(scale=10, size=100_000)             # a very skewed population
means = [rng.choice(pop, 50).mean() for _ in range(2000)] # 2000 samples of size 50
print("Population mean:", round(pop.mean(), 2), " skew:", round(stats.skew(pop), 2))
print("Mean of sample means:", round(np.mean(means), 2), " skew:", round(stats.skew(means), 2))
Output
Population mean: 9.96  skew: 1.98
Mean of sample means: 9.95  skew: 0.2

Explanation: The population is strongly skewed (skew ≈ 2), yet the averages of samples are almost symmetric and centred on the true mean. The CLT says sample means are approximately normal for large enough samples (often n ≥ 30), which is why normal-based confidence intervals and hypothesis tests work so widely.

Series

Maths & Statistics series: Descriptive Statistics · Probability · Statistical Distributions · Inferential Statistics · Hypothesis Testing · Linear Algebra · Calculus

Interview Questions

Q: What is standard error?
The standard deviation of a sample statistic (such as the mean) across repeated samples: s/√n.

Q: What does the Central Limit Theorem say?
The distribution of sample means approaches normal as the sample size grows, whatever the population shape.

Practice Exercises

  1. Compute a 99% confidence interval for the same sample. Is it wider or narrower?
  2. Repeat the CLT simulation with sample size 5 and 200.

Summary

Inferential statistics estimates population values from samples. Standard errors and confidence intervals express uncertainty, and the Central Limit Theorem explains why sample means behave normally.

Next: Hypothesis Testing

About Machine Learning

Check Also

Statistical Distributions: Normal, Binomial, Poisson with Python

Normal, binomial, Poisson, uniform and exponential distributions with scipy.stats examples and their use in machine learning.