Chapter 2: approximate posterior via simulation
Chapter 2: approximate posterior via simulation
To simulate this probability, and represent our information regarding the balls’ urn or origin, we will simply draw pairs of balls from both urns. After drawing balls, we then determine, of all the pairs that were both red, what proportion had come from the first urn. To guarantee that we will have drawn a minimum number of pairs that meet our criterion, we will make use of a while-loop:
C=[0 0]; %initialize counter vector with zeros
REPS=100000; Nballs1=98; Nballs2=148;
while sum(C)<REPS,
D1=randperm(Nballs1); D2=randperm(Nballs2);
C(1)=C(1)+and(D1(1)<=54,D1(2)<=54);
C(2)=C(2)+and(D2(1)<=74,D2(2)<=74); end
C(1)/sum(C)