An interesting application of conditional probability is the Monty-Hall problem, whose solution intrigued many, including career mathematicians (life is hard!). There is a lot of trivia around this problem in the internet, a good place to start would be the Wikipedia article here: https://en.wikipedia.org/wiki/Monty_Hall_problem

In this project we will understand the solution of this problem using simulations.

1 Monty-Hall Three doors

Run a simulation to check that the probablility of winning increases to 2/3 if we switch doors at step two in the regular 3-door Monty-Hall problem.

Set up the experiment two functions “monty_3doors_noswitch” and “monty_3doors_switch” (these functions will have no input values):

monty_3doors_noswitch <- function(){

  doors = c(1,2,3) # had 3 doors
  
ch1 = sample(doors, 1) # 1st choice: pick one door at random
crct1 = sample(doors, 1) # the correct box
  
# Assume When making the second choice, you stick with the original choice and you are RIGHT
  
# let X be a binary variable that takes the value 1 if the choice is correct and 0 if incorrect
x = 0
x = ifelse(ch1 == crct1,1,0) # you stick with the original choice and you are RIGHT
x
}

no_of_Successes = replicate(1000000, monty_3doors_noswitch())
prob = sum(no_of_Successes)/1000000
probability = prob
probability
## [1] 0.333848
monty_3doors_switch <- function(){
  
  doors = c(1,2,3) # had 3 doors
  
ch = sample(doors, 1) # 1st choice: pick one door at random
crct = sample(doors, 1) # the correct box
  
# When making the second choice, you stick with the original choice and you are WRONG.
  
# let X be a binary variable that takes the value 1 if the choice is correct and 0 if incorrect
x = 0
x = ifelse(ch != crct,1,0) # you stick with the original choice and you are WRONG.
x
  
}
 
no_of_Successes = replicate(1000000, monty_3doors_switch())
prob = sum(no_of_Successes)/1000000
probabilty = prob
prob
## [1] 0.666377

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.

#No switch:The theoretical probability of success is 1/3 = 0.3333
#Therefore, approximately the same results from the simulation = 0.3323

#Switch: The theoretical probability of success is 2/3 = 0.6667.
#Therefore, approximately the same results from the simulation = 0.6673.

2 Monty-Hall with Ten doors.

Repeat the Monty Hall experiment now with 10 doors. Recall the game is as follows: Step 1: you choose one door at random. Step 2: Monty opens 8 (out of 9 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 no input values):

monty_10doors_noswitch <- function(){
  Prize_Door_Number<- sample(1:10, size=1000, replace=T)
choose_random_door_No <- sample(1:10, size=1000, replace=T)
  
Winner<- rep(0,1000)

#In case of no switch prize win when Prize_Door_Number same as choosen_random_door_No
Winner[Prize_Door_Number==choose_random_door_No]=1
return(paste("probability of winning for Not switching Door = ",sum(Winner)/1000))
}

monty_10doors_switch <- function(){
  Prize_Door_Number<- sample(1:10, size=1000, replace=T)
choose_random_door_No <- sample(1:10, size=1000, replace=T)
  
Winner<- rep(0,1000)

#In case of switch prize win when Prize_Door_Number is not same as choosen_random_door_No

Winner[Prize_Door_Number!=choose_random_door_No]=1
return(paste("probability of winning for switching Door = ",sum(Winner)/1000))
}

monty_10doors_noswitch()
## [1] "probability of winning for Not switching Door =  0.104"
monty_10doors_switch()
## [1] "probability of winning for switching Door =  0.925"

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.

#The probability of winning for not switching door was 0.097 which is 9.7%.
#The probability of winning for not switching door was 0.891 which is 8.91%.

3 Monty-Hall 10-doors (modified).

Consider the following modified Monty-Hall game with 10 doors. Step 1: you choose one door at random. Step 2: Monty opens 7 (out of 9 doors) that do not have the prize. Step 3: you either stick with your original choice, or choose between one of the two unopened doors.

Set up the experiment two functions “monty_10doors_mod_noswitch” and “monty_10doors_mod_switch” (these functions will have no input values):

monty_10doors_mod_noswitch <- function(){
  Prize_Door_Number<- sample(1:10, size=1000, replace=T)
choose_random_door_No <- sample(1:10, size=1000, replace=T)
  
Winner<- rep(0,1000)

#In case of no switch prize win when Prize_Door_Number same as choosen_random_door_No
Winner[Prize_Door_Number==choose_random_door_No]=1
return(paste("probability of winning for Not switching Door = ",sum(Winner)/1000))
}

monty_10doors_mod_switch <- function(){
  Prize_Door_Number<- sample(1:10, size=1000, replace=T)
choose_random_door_No <- sample(1:10, size=1000, replace=T)
  
Winner<- rep(0,1000)

#In case of switch prize win when Prize_Door_Number is not same as choosen_random_door_No

Winner[Prize_Door_Number!=choose_random_door_No]=1
return(paste("probability of winning for switching Door = ",sum(Winner)/1000))
}

Use your two functions and the replicate function to compute the empirical probablility of winning for the two experiments. The computation of the theoretical probability in this case might not be completely obvious, however, use your empirical probability to make a guess.

#The probability of winning for not switching door is 10.2%.
#The probability of winning for switching door is 89.9%.

Not for submission: Play with this modified setup, for example Monty opens 6 doors at step 2 etc.

4 (Bonus) Monty Hall with n-doors.

This is for your curiosity, you don’t have to turn this in. However, if you work this general case out, you can use it to solve the earlier versions of the problem.

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_ndoors_noswitch” and “monty_ndoors_switch” (these functions will have input value as n):

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.