My Moty hall simulation in R gives wrong results

14 Views Asked by At

I am working on Monty hall simulation, I want to simulate this scenario. Karla (it is the name) always decides to change her initial guess to the second door that is still not opened after first reveal. The probability of winning should be around 0.66, but it shows me different number and I can not figure out why.

Karla_simulation <- function() {
  # Assign the prize
  
  price_position <- sample(1:3,1)
  # Pick a door
  pick1 <- sample(1:3, 1)
  reveal <- sample(setdiff(1:3,c(vyber1, which(pozicia_ceny == 1))),1)
  if (price_position!=pick1 & price_position!=reveal){
    return(1)
  }
  else{
    return(0)
  }
}


repetitions <- 100000
Karla_wins <- numeric(repetitions)
for (i in seq_along(Karla_wins)) {
  Karla_wins[i] <- Karla_simulation()
  
}

propability <-sum(Karla_wins)/repetitions
0

There are 0 best solutions below