library(dplyr)Monty Hall Problem
There are 3 doors (A,B,C) and only 1 door has a car behind it and the other two doors have goats behind them. Say, you have selected door A - now, the game show host opens B and shows it to be a goat. Now, you have an option to switch the door from A to C. should you switch ?

This seemingly simple problem statement has tortured novices and pros alike. To answer this question, we need to know how the odds change for winning if we switch vs if we don’t. When we don’t switch the probability of winning would remain at 1/3. When we switch there is 1/3 chance of selecting a car and losing and 2/3 chance of choosing a goat and winning (due to switch), so switching nearly doubles our chances.Thank you for the extra 33.3%. 1
I have simulated this scenario below in R
set.seed(1)
doors = c('A', 'B', 'C')
car_door = sample(doors, size = 10000, replace = T)
choosen_door = sample(doors, size = 10000, replace = T)set.seed(1)
tibble(
car = car_door,
choosen = choosen_door) |>
rowwise() |>
mutate(door_revealed = sample(setdiff(doors, c(car, choosen)), 1)
) |>
mutate(switch = setdiff(doors, c(choosen, door_revealed))) |>
ungroup()|>
mutate(remain = choosen) %>%
mutate(switch_win = ifelse(car == switch, 1, 0),
remain_win = ifelse(car == remain, 1, 0)
) |>
summarize(
switch_win_rate = sum(switch_win)/n(),
remain_win_rate = sum(remain_win)/n()
)# A tibble: 1 × 2
switch_win_rate remain_win_rate
<dbl> <dbl>
1 0.665 0.335