LoslegenKostenlos loslegen

Win probability with "switch"

Now let us code the situation where the contestant initially picks Door #1, and then upon the goat reveal, they switch to the remaining door.

Again, first, we will code just one iteration. Then, we will incorporate this into a for loop to run the process repeatedly in order to obtain a simulated estimate of the true win probability.

Diese Übung ist Teil des Kurses

Probability Puzzles in R

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

set.seed(1)
prize <- sample(doors,1)
initial_choice <- 1

# Use the reveal_door function to do the reveal
reveal <- reveal_door(___, ___, ___)

# Switch to the remaining door
final_choice <- ___
print(final_choice)

# Check whether the final choice equals the prize
if(___){
  print("The final choice is correct!")
}
Code bearbeiten und ausführen