Changing the mean of normal distributions
In this exercise, you'll use sampling to calculate the 95% confidence interval of the average height of American adult males. Recall from the lesson that the heights of American adult males are normally distributed with a mean of 177 centimeters and a standard deviation of eight centimeters.
After sampling from the distribution with the above sample statistics, you'll change the mean of the heights to 185 centimeters without changing the standard deviation to explore what happens to the mean and confidence interval of the average height after sampling again.
The following have been imported for you: random
, NumPy as np
, and SciPy's stats
module as st
.
Cet exercice fait partie du cours
Monte Carlo Simulations in Python
Instructions
- Sample 1,000 times from the normal distribution where the mean is 177 and the standard deviation is eight; store the results in
heights_177_8
. - Sample 1,000 times from the normal distribution where the mean is 185 and the standard deviation is eight; store the results in
heights_185_8
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
random.seed(1222)
# Sample 1,000 times from the normal distribution where the mean is 177
heights_177_8 = ____
print(np.mean(heights_177_8))
upper = np.quantile(heights_177_8, 0.975)
lower = np.quantile(heights_177_8, 0.025)
print([lower, upper])
# Sample 1,000 times from the normal distribution where the mean is 185
heights_185_8 = ____
print(np.mean(heights_185_8))
upper = np.quantile(heights_185_8, 0.975)
lower = np.quantile(heights_185_8, 0.025)
print([lower, upper])