Sampling and Estimation
Topic - In real-world data science, measuring an entire population is rarely feasible due to operational constraints. Instead, we use sampling distributions to estimate unknown population parameters. Point estimation produces a single best-guess statistic, while interval estimation constructs a confidence interval bounded by a margin of error.
1. Population vs. Sample & The Need for Sampling
- Population: The complete collection of all elements, individuals, or items under study (e.g., all manufactured batteries from a factory). Characteristics of a population are called parameters (mean , variance , proportion ).
- Sample: A representative subset drawn from the population. Numerical summaries computed from a sample are called statistics (sample mean , sample variance , sample proportion ).
The Practical Need to Sample
- Destructive Testing: Evaluating battery lifespan or the tensile strength of an alloy exhausts the product. Testing the whole population leaves zero inventory to sell.
- Resource Constraints: Gathering data on large populations (such as all citizens in a country) is cost-prohibitive and computationally intractable.
- Efficiency: An appropriately sized, unbiased random sample provides precise, mathematically bounded estimates with minimal variance.
Probabilistic Sampling Techniques
Sampling methods dictate how observations are selected from a population. In statistical inference, probabilistic sampling ensures every element in the target population has a known, non-zero probability of selection, eliminating systematic selection bias.
| Sampling Method | Operational Mechanism | Key Characteristic / Use Case |
|---|---|---|
| Simple Random (SRS) | Every individual unit in the population has an equal probability of selection. | Baseline random sampling; standard train/test dataset splits. |
| Stratified Sampling | Population is divided into homogeneous, non-overlapping subgroups (strata); random samples are drawn proportionally from each stratum. | Used when data is heterogeneous across sub-populations; ensures minority classes are represented (e.g., StratifiedKFold). |
| Systematic Sampling | The first unit is selected randomly, and subsequent units are drawn at fixed periodic intervals (). | Easy to implement for physical audits, large-scale quality control on assembly lines, or continuous data streams. |
| Cluster Sampling | Population is divided into naturally occurring heterogeneous subgroups (clusters); entire clusters are randomly selected as sample points. | Cost-effective when the population is widely dispersed geographically; sampling entire schools or regional centers instead of scattered individuals. |
Simple Random Sampling: With vs. Without Replacement
- Simple Random Sampling Without Replacement (SRSWOR): Once a unit is selected, it is not returned to the population pool.
- From a population of units, the number of distinct possible samples of size is:
- The probability of selecting any specific sample configuration is .
- Python equivalent:
random.sample(population, k=n).
- Simple Random Sampling With Replacement (SRSWR): Once a unit is selected and recorded, it is returned to the population pool, meaning an observation can be drawn multiple times.
- The number of possible ordered samples of size from population is:
- The probability of selecting any specific sequence is .
- Crucial for simulation studies, Monte Carlo simulations, and bootstrapping.
- Python equivalent:
random.choices(population, k=n).
Resampling Methods
Resampling is an empirical, non-parametric methodology where repeated samples are drawn directly from an available observed sample rather than the underlying population:
- Bootstrap Resampling: Repeatedly drawing samples of size with replacement from the observed dataset. It estimates the empirical sampling distribution of any statistic (mean, median, variance) without requiring parametric normality assumptions. It forms the computational foundation of Bootstrap Aggregating (Bagging) in ensemble models like Random Forests.
- Jackknife Resampling: Systematically recomputing the estimator while iteratively leaving out one observation at a time ( subsamples of size ). Primarily employed for estimating the bias and standard error of complex parameter estimators.
2. Sampling Distributions & The Central Limit Theorem (CLT)
When drawing independent random samples of size from a population, the calculated sample statistics will naturally fluctuate. This variation across repeated samples is called sampling variability.
The probability distribution of these sample means is the Sampling Distribution of the Mean.
The Central Limit Theorem Formulation
The Central Limit Theorem (CLT)
Regardless of the underlying population distribution (whether Normal, Poisson, Binomial, or Uniform), as the sample size becomes sufficiently large (), the sampling distribution of the sample mean approaches a Normal Distribution:
Where is called the Standard Error of the Mean (SE).
Converting the sample mean to a standard normal variable:
If the population standard deviation is unknown, we substitute the sample standard deviation , yielding for large samples ().
3. Point Estimation
A point estimate uses a single statistic computed from sample observations to estimate an unknown population parameter.
Motivating Question: Average Income of a 27-Year-Old in London
- Question: What would be the average income of a 27-year-old in London? How would you calculate it?
- The Trivial Approach: Collect income figures for every single 27-year-old living in London and compute their exact mean ().
- The Operational Reality: Surveying the entire population is unfeasible due to time, labor, and computational costs.
- The Statistical Solution: Draw a representative random sample of size , calculate the sample mean , and use as our point estimate for the population mean .
| Parameter to Estimate | Unbiased Point Estimator | Mathematical Formula |
|---|---|---|
| Population Mean () | Sample Mean () | |
| Population Variance () | Sample Variance () | |
| Population Proportion () | Sample Proportion () |
Sampling Error
The point estimate will differ from the true population parameter due to random chance. The absolute magnitude of this discrepancy is the Sampling Error:
Increasing the sample size consistently drives down the standard error (), decreasing sampling error.
Worked Example: Morning Temperature Sampling Error
- Population Mean ():
- Sample Data ( mornings):
- Sample Mean ():
- Sampling Error:
4. Interval Estimation & Confidence Intervals
Because a point estimate rarely matches the true parameter exactly, Interval Estimation provides a range of plausible values associated with a specified confidence level ().
Derivation for Population Mean ()
From the Central Limit Theorem, the probability that the standardized statistic falls between two critical values and is :
Rearranging the inequality:
Thus, the Confidence Interval is:
Where is the Margin of Error.
Critical Values for Common Confidence Levels
- 90% Confidence (α = 0.10)
- 95% Confidence (α = 0.05)
- 99% Confidence (α = 0.01)
Computing Critical Z-Values in Python
In Python, critical values are computed using scipy.stats:
scipy.stats.norm.ppf(1 - alpha / 2): Percent Point Function (inverse of CDF, returns the -score with cumulative area ).scipy.stats.norm.isf(alpha / 2): Inverse Survival Function (returns the upper-tail critical -score directly).
Width vs. Confidence Tradeoff
As the confidence level increases (e.g., from 90% to 99%), grows larger, making the interval wider. A higher degree of certainty requires a wider net.
5. Confidence Intervals for Proportions
For categorical variables (such as defective items or churn status), the sampling distribution of the sample proportion follows an approximate normal distribution for large samples:
The Confidence Interval for Proportion is:
6. Determining Sample Size from Margin of Error
When designing an experiment or survey, a primary goal is to determine how many observations must be sampled to guarantee a maximum tolerable margin of error :
Error vs. Sample Size Relationship
Because is inversely proportional to , halving the target margin of error requires a fourfold increase in the sample size.
Verification Example: Coal Ash Testing
Problem: 100 bags of coal are tested and exhibit a standard deviation of ().
- Margin of Error at 90% Confidence ():
- Reverse Sample Size Calculation: Given a target margin of error , verify the required sample size:
7. Numerical Problem Walkthroughs
Scenario A: Portfolio Point Estimate
Problem: A financial firm manages portfolios. A sample of portfolios is audited, and are found underperforming. Estimate the total number of underperforming portfolios in the firm.
- Sample Proportion:
- Total Estimate: portfolios.
Scenario B: Average Income Confidence Interval
Problem: A sample of twenty-seven-year-olds in London has an average income of GBP with population standard deviation GBP. Calculate the 95% Confidence Interval. Furthermore, obtain the 90% and 99% confidence intervals and logically explain which is the widest.
- Given: , , .
- Standard Error: GBP.
- 95% Confidence Interval ():
- 90% Confidence Interval ():
- 99% Confidence Interval ():
- Width Comparison: The 99% confidence interval is the widest (width ), followed by the 95% interval (width ), and the 90% interval (width ). To have higher confidence (99% certainty vs. 90% certainty) that the interval captures the fixed population mean , the interval must cover a broader range of possible values.
- Interpretation: If we repeat this sampling process many times, roughly 95% of the calculated intervals will contain the true mean income. (It is incorrect to say there is a 95% chance that the true mean is inside this specific fixed interval, as the parameter is a fixed constant, not a random variable).
Scenario C: Proportion Confidence Interval (Audited Portfolios)
Problem: A financial firm manages 50 portfolios. An audit of portfolios reveals that are underperforming. Construct a 99% confidence interval for the true population proportion of underperforming portfolios.
- Given: ,
- Critical Value: For 99% confidence,
- Standard Error of Proportion:
- Margin of Error:
- Confidence Interval:
- Interpretation: With 99% confidence, the true proportion of underperforming portfolios across the firm lies between approximately 26.8% and 96.3%.
8. Implementation Lab
import numpy as np
from scipy import stats
# 1. Confidence Interval for Mean (London Income Scenario)
n = 250
mean_val = 45000
std_val = 4000
conf_level = 0.95
# Calculate scale = std / sqrt(n)
ci_mean = stats.norm.interval(conf_level, loc=mean_val, scale=std_val / np.sqrt(n))
print(f"95% CI for Mean: {ci_mean}")
# 2. Confidence Interval for Proportion (Portfolios Scenario)
n_port = 13
x_port = 8
p_hat = x_port / n_port
se_prop = np.sqrt((p_hat * (1 - p_hat)) / n_port)
ci_prop = stats.norm.interval(0.99, loc=p_hat, scale=se_prop)
print(f"99% CI for Proportion: {ci_prop}")
Key Takeaways
- CLT Guarantees Normality: The sampling distribution of the mean is normal for , even if the original population distribution is non-normal.
- Confidence vs. Probability: The parameter is fixed. A 95% confidence interval means that across repeated sampling experiments, 95% of constructed intervals capture .
- Controlling Margin of Error: To cut the margin of error in half, you must quadruple the sample size ().
Next Section: Hypothesis Testing Foundations - learning to evaluate statistical claims, understand errors, and compute test power.