In: Statistics and Probability
1. Three players, A,B, and C, each flip their coins until one person has a different result from the others. The person having the different result wins.
(a) Using R, simulate this experiment 10000 times and give the resulting estimate of P(A wins).
# The possible outcomes when three coins are simultaneously flipped by A, B,C are :
Heads/Tails | HHH | HHT | HTH | HTT | THH | THT | TTH | TTT |
1/0 | 111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
# Let 1=Head=H and 0=Tail=T
#If anyone flips a coin, the probability that head(or tail) shows
up is half(1/2).
#Therefore, it is like Bernoulli trial for each
individual; with probability of success p=1/2.
# Also, each individual independently flips the coin.
# Bernoulli(p) is equivalent to Binomial(1,p)
p=1/2
A=rbinom(10000,1,p)
B=rbinom(10000,1,p)
C=rbinom(10000,1,p)
#data.frame(A,B,C)
M=cbind(A,B,C)
head(M)
A B C
[1,] 0 1 0
[2,] 1 0 1
[3,] 0 0 0
[4,] 1 1 1
[5,] 1 1 1
[6,] 1 0 1
M[which(A==B & B==C),] ## This will give positions(row
number) where elements are '000' or '111'.
head(M[which(A==B & B==C),])
# A B C
#[1,] 0 0 0
#[2,] 1 1 1
#[3,] 1 1 1
#[4,] 1 1 1
#[5,] 0 0 0
#[6,] 0 0 0
length(which(A==B & B==C)) ## This total number of outcomes
where nobody wins
#[1] 2505
# which(A!=B & B==C)
M[which(A!=B & B==C),] ## This will give positions(row number)
where elements are '011' or
'100'. i.e. Position when A
wins.
unique(M[which(A!=B & B==C),])
# A B C
#[1,] 0 1 1
#[2,] 1 0 0
head(M[which(A!=B & B==C),])
# A B C
#[1,] 0 1 1
#[2,] 1 0 0
#[3,] 0 1 1
#[4,] 1 0 0
#[5,] 0 1 1
#[6,] 1 0 0
length(which(A!=B & B==C))
[1] 2542
# Estimate of Probability that A
wins:
# Using fundamental definition of probability
# Probabilty= (number of favourable outcomes in an event) / (Total
number of outcomes)
# Total outcomes=10000
PA=length(which(A!=B & B==C))/10000
PA
#[1] 0.2542
PB=length(which(B!=A & A==C))/10000
PB
#[1] 0.2504
PC=length(which(C!=A & A==B))/10000
PC
#[1] 0.2449
lenNO=length(which(A==B & B==C))
lenNO
#[1] 2505
#P(Nobody wins)
lenNO/10000
#[1] 0.2505
1-(PA+PB+PC)
#[1] 0.2505