Robert_V._Hogg,_Joseph_W._McKean,_Allen_T._Craig

(Jacob Rumans) #1
32 Probability and Distributions

at 0. The commandsample(rngA,1,pr=pA)draws a sample of size 1 fromrngA
with pmfpA. Each execution of the while loop returns one complete game. Further,
the executions are independent of one another.

abgame <- function(){
rngA <- c(0,1); pA <- rep(1/2,2); rngB <- 1:6; pB <- rep(1/6,6)
ic <- 0; Awin <- 0; Bwin <- 0
while(ic == 0){
x <- sample(rngA,1,pr=pA)
if(x==1){
ic <- 1; Awin <- 1
} else {
y <- sample(rngB,1,pr=pB)
if(y <= 4){ic <- 1; Bwin <- 1}
}
}
return(c(Awin,Bwin))
}

Notice that one and only one ofAwinorBwinreceives the value 1 depending on
whetherornotAorBwins. The next R segment simulates the game 10,000 times
and computes the estimate thatAwins along with the error of estimation.


ind <- 0; nsims <- 10000
for(i in 1:nsims){
seeA <- abgame ()
if(seeA[1] == 1){ind <- ind + 1}
}
estpA <- ind/nsims
err <- 1.96sqrt(estpA(1-estpA)/nsims)
estpA; err


An execution of this code resulted inestpA = 0.6001anderr = 0.0096.Asnoted
above the probability thatAwins is 0.6 which is in the interval 0. 6001 ± 0 .0096. As
discussed in Chapter 4, we expect this to occur 95% of the time when using such a
confidence interval.


EXERCISES

1.4.1.IfP(A 1 )>0andifA 2 ,A 3 ,A 4 ,...are mutually disjoint sets, show that

P(A 2 ∪A 3 ∪···|A 1 )=P(A 2 |A 1 )+P(A 3 |A 1 )+···.

1.4.2.Assume thatP(A 1 ∩A 2 ∩A 3 )>0. Prove that


P(A 1 ∩A 2 ∩A 3 ∩A 4 )=P(A 1 )P(A 2 |A 1 )P(A 3 |A 1 ∩A 2 )P(A 4 |A 1 ∩A 2 ∩A 3 ).
Free download pdf