Answer to Question #136859 in Statistics and Probability for nati

Question #136859
In R studio

# 4. BONUS: Monty Hall with n-doors.
Repeat the Monty Hall experiment now with n doors. Recall the game is as follows:
Step 1: you choose one door at random.
Step 2: Monty opens n-2 (out of n-1 doors) that do not have the prize.
Step 3: you either switch or don't switch.

Set up the experiment two functions "monty_10doors_noswitch" and "monty_10doors_switch" (these functions will have input value as n):

```{r}
monty_ndoors_noswitch <- function(n){

}

monty_ndoors_switch <- function(n){

}
```

Use your two functions and the replicate function to compute the empirical probablility of winning for the two experiments.
Compare your answers with the actual theoretical predictions.
```{r}

```
1
Expert's answer
2020-10-07T15:22:27-0400

no switch:


# Let "n" be the number of doors available


monty_ndoors_noswitch = function(n){


  doors = 1:n # Total available doors
  
  choice = sample(doors, 1) # 1st choice: pick one door at random
  correct = sample(doors, 1) # the correct box
  
  # After the 1st pick, "n-1" doors are left. "n-2" doors that don't have the prize are opened so that only 2 doors remain closed i.e. the choice made at first and one other door. The correct door with a prize must be one of the two
  
  # if the first pick was correct, any one of the remaining "n-1" doors is left. but if the first choice is wrong, then the door with the prize is left and the others removed.
  
  last_choice = ifelse(choice == correct, sample(doors[doors!= correct], 1), correct)


  # let X be a binary variable that takes the value 1 if the choice is correct and 0 if incorrect
  x = 0 
  
  # you win if you stick with the original choice
  
  x = ifelse(choice == correct ,1,0) 
  x
}

switch:


monty_ndoors_switch  = function(n){
  


  doors = 1:n # Total available doors
  
  choice = sample(doors, 1) # 1st choice: pick one door at random
  correct = sample(doors, 1) # the correct box
  
   # After the 1st pick, "n-1" doors are left. "n-2" doors that don't have the prize are opened so that only 2 doors remain closed i.e. the choice made at first and one other door. The correct door with a prize must be one of the two
  
  # if the first pick was correct, any one of the remaining "n-1" doors is left. but if the first choice is wrong, then the door with the prize is left and the others removed.
  
  last_door = ifelse(choice == correct, sample(doors[doors!= correct], 1), correct)
  
  # let X be a binary variable that takes the value 1 if the choice is correct and 0 if incorrect
  x = 0 
  
  # you win if you shift from the original choice to the other remaining door
  
  x = ifelse(last_door==correct ,1,0) 
  x
}

part 3:


To verify, let "n = 3" and run "1,000,000" simulations


we expect the probability of winning if you stick with the initial door to be "0.3333".


wins = replicate(1000000, monty_ndoors_noswitch(3))
sum(wins)/1000000


we get "P=0.3333" from the simulation.



we expect the probability of winning if you stick with the initial door to be "0.6667"


wins = replicate(1000000, monty_ndoors_switch(3))
sum(wins)/1000000


we get "P = 0.6669" from the simulation


Therefore, the empirical probabilities are consistent with the theoretical


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS