Get startedGet started for free

Exercise 9. American Roulette Monte Carlo again

Create a Monte Carlo simulation that generates 10,000 outcomes of \(S\), the average outcome from 10,000 bets on green.

Compute the average and standard deviation of the resulting list to confirm the results from previous exercises using the Central Limit Theorem.

This exercise is part of the course

HarvardX Data Science - Probability (PH125.3x)

View Course

Exercise instructions

  • Use the replicate function to model 10,000 iterations of a series of 10,000 bets.
  • Each iteration inside replicate should simulate 10,000 bets and determine the average outcome of those 10,000 bets. If you forget to take the mean, DataCamp will crash with a "Session Expired" error.
  • Find the average of the 10,000 average outcomes. Print this value to the console.
  • Compute the standard deviation of the 10,000 simulations. Print this value to the console.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

## Make sure you fully follow instructions, including printing values to the console and correctly running the `replicate` loop. If not, you may encounter "Session Expired" errors.

# The variable `n` specifies the number of independent bets on green
n <- 10000

# The variable `B` specifies the number of times we want the simulation to run
B <- 10000

# Use the `set.seed` function to make sure your answer matches the expected result after random number generation
set.seed(1)

# Generate a vector `S` that contains the the average outcomes of 10,000 bets modeled 10,000 times





# Compute the average of `S`


# Compute the standard deviation of `S`
Edit and Run Code