Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Monte Carlo Simulations in Python

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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