Get startedGet started for free

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.

This exercise is part of the course

Monte Carlo Simulations in Python

View Course

Exercise instructions

  • Sample 1,000 times from the normal distribution where the mean is 177 and the standard deviation is eight; store the results inheights_177_8.
  • Sample 1,000 times from the normal distribution where the mean is 185 and the standard deviation is eight; store the results inheights_185_8.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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])
Edit and Run Code