1. Learn
  2. /
  3. Courses
  4. /
  5. HarvardX Data Science Module 4 - Inference and Modeling

Exercise

Exercise 5 - Monte Carlo Simulation for Heights

Now run a Monte Carlo simulation in which you compute 10,000 confidence intervals as you have just done. What proportion of these intervals include \(\mu\)?

Instructions

100 XP
  • Use the replicate function to replicate the sample code for B <- 10000 simulations. Save the results of the replicated code to a variable called res. The replicated code should complete the following steps: -1. Use the sample function to sample N values from x. Save the sampled heights as a vector called X. -2. Create an object called interval that contains the 95% confidence interval for each of the samples. Use the same formula you used in the previous exercise to calculate this interval. -3. Use the between function to determine if \(\mu\) is contained within the confidence interval of that simulation.
  • Finally, use the mean function to determine the proportion of results in res that contain mu.