I calculated the probability manually & the result should be 0.39, I also tried to use replicate & sample & get the same output in R but I am making one mistake, I am unable to get right output in 5,6,7 matches output below. I get correct output when there are only 4 matches but I am unable to tweak R code to consider only first 4 wins in matches 5,6,7 (m5,m6,m7). Below is my try.
teama_wins<- function(variables) {
m4 <- mean(replicate(1000,sum(sample(c(0,1), 4, replace = TRUE, prob = c(0.55, 0.45)))==4))
m5 <- mean(replicate(1000,sum(sample(c(0,1), 5, replace = TRUE, prob = c(0.55, 0.45)))==4))
m6 <- mean(replicate(1000,sum(sample(c(0,1), 6, replace = TRUE, prob = c(0.55, 0.45)))==4))
m7 <- mean(replicate(1000,sum(sample(c(0,1), 7, replace = TRUE, prob = c(0.55, 0.45)))==4))
return(sum(m4,m5,m6,m7))
}
teama_wins()
Mathematically it doesn't matter whether the games after the series is decided are played or not, so you can just change the code to:
teama_wins<- function(variables) {
mean(replicate(1000,sum(sample(c(0,1), 7, replace = TRUE, prob = c(0.55, 0.45)))>=4))
}
teama_wins()
Note that this is now checking that at least four games were won by team A, rather than exactly 4 in each scenario.
I found that I needed to increase the number of samples to 10,000 to get reasonably close to the expected answer, but it then gets ~0.39 as expected