CommencerCommencer gratuitement

Sample means follow a normal distribution

In the previous exercise, we generated a population that followed a binomial distribution, chose 20 random samples from the population, and calculated the sample mean. Now we're going to test some other probability distributions to see the shape of the sample means.

From the scipy.stats library, we've loaded the poisson and geom objects and the describe() function. We've also imported matplotlib.pyplot as plt and numpy as np.

As you'll see, the shape of the distribution of the means is the same even though the samples are generated from different distributions.

Cet exercice fait partie du cours

Foundations of Probability in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Generate the population
population = geom.rvs(p=0.5, size=1000)

# Create list for sample means
sample_means = []
for _ in range(3000):
	# Take 20 values from the population
    sample = np.random.choice(population, ____)
    # Calculate the sample mean
    sample_means.append(describe(____).____)

# Plot the histogram
plt.____(sample_means)
plt.show()
Modifier et exécuter le code