Loading content...
The Sampling Distribution of the Mean is one of the most powerful and elegant concepts in probability theory and statistical inference. It forms the theoretical foundation for understanding how sample statistics behave when drawn repeatedly from a population.
When we draw many random samples from a population, each sample produces its own mean. The distribution of these sample means follows predictable patterns governed by the Central Limit Theorem (CLT)—one of the cornerstones of modern statistics. Remarkably, regardless of the shape of the underlying population distribution, the distribution of sample means approaches a normal distribution as sample size increases.
Core Concept: Given a population with mean μ and standard deviation σ, the sampling distribution of the mean has the following properties:
$$\text{Mean of sample means} = \mu$$
$$\text{Standard error} = \frac{\sigma}{\sqrt{n}}$$
where n is the sample size.
Your Task: Implement a function that simulates this fundamental statistical phenomenon. The function should:
Supported Distributions:
np.random.uniform(0, 1, sample_size)np.random.exponential(1, sample_size)The theoretical expectation is that as the number of samples increases, the grand mean should converge toward the true population mean:
Round the final result to 4 decimal places.
num_samples = 1000
sample_size = 30
distribution = 'uniform'0.4996We generate 1000 independent samples, each containing 30 random values drawn from a Uniform(0, 1) distribution. For each sample, we compute the mean. Finally, we calculate the mean of all 1000 sample means.
The Uniform(0, 1) distribution has a theoretical mean of 0.5. With 1000 samples of size 30, the Central Limit Theorem ensures that the grand mean converges very close to this theoretical value. The result of 0.4996 demonstrates this convergence, with only a 0.08% deviation from the expected value.
num_samples = 500
sample_size = 50
distribution = 'exponential'1.0045We draw 500 independent samples from an Exponential distribution with scale parameter 1. Each sample contains 50 observations. The mean is computed for each sample, and then the overall mean of these 500 sample means is calculated.
The Exponential(scale=1) distribution has a theoretical mean of 1.0. The result of 1.0045 shows excellent convergence to this expected value, illustrating how the sampling distribution of the mean centers around the population mean regardless of the underlying distribution's shape.
num_samples = 100
sample_size = 20
distribution = 'uniform'0.4986With only 100 samples of size 20 each, we have fewer total observations compared to the previous examples. The function draws from Uniform(0, 1) and computes the grand mean of all sample means.
The result of 0.4986 is slightly further from the theoretical mean of 0.5 (0.28% deviation). This demonstrates that with fewer samples, we expect more variability in our estimate—a practical illustration of how sample size affects the precision of statistical estimates.
Constraints