Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Foundations of Probability in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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()
Code bewerken en uitvoeren