Answer to Question #136848 in Statistics and Probability for nati

Question #136848
In R studio
# 1. Monty-Hall Three doors

Recall the Monty-Hall game with three doors, discussed in class. Run a simulation to check that the probablility of winning increases to 2/3 if we switch doors at step two.

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

```{r}
monty_3doors_noswitch <- function(){

}

monty_3doors_switch <- function(){

}

```

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-06T17:39:54-0400

solutions:


part 1: no switch


monty_3doors_noswitch <- function(){

  doors = c(1,2,3) # had 3 doors
  
  choice1 = sample(doors, 1) # 1st choice: pick one door at random
  correct = 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(choice1 == correct,1,0) # you stick with the original choice and you are RIGHT
  x
}

part 2: switch


monty_3doors_switch = function(){

  doors = c(1,2,3) # had 3 doors
  
  choice = sample(doors, 1) # 1st choice: pick one door at random
  correct = 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(choice != correct,1,0) # you stick with the original choice and you are WRONG.
  x
}

part 3: empirical probablility of winning for the two experiments.


no switch: run 1 million simulations and obtain the probability = 0.333826

number_of_successes = replicate(1000000, monty_3doors_noswitch()) 
probability = sum(number_of_successes)/1000000
probability 


switch: run 1 million simulations and obtain the probability = 0.665828

number_of_successes = replicate(1000000, monty_3doors_noswitch()) 
probability = sum(number_of_successes)/1000000
probability

part 4: Compare your answers with the actual theoretical predictions.


no switch: The theoretical probability of success is

"\\frac{1}{3} = 0.3333"
  • This is approximately the same results from the simulation "=0.3338"


switch: The theoretical probability of success is

"\\frac{2}{3} = 0.6667"
  • This is approximately the same results from the simulation "=0.6658"

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