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.
This exercise is part of the course
Probability Puzzles in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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!")
}