Chapter 2: posterior over urns
To perform this simulation we will simply add a layer of complexity to existing simulations, inserting a coin-toss at the start of each simulation run. The outcome of the coin-toss will then determine from which of the two simulated urns we draw:
REPS=100000;
Nballs1=98; Nballs2=148;
S=nan(REPS,1); %initialize success vector with NaN values
for n=1:REPS,
if rand<.5, S(n)=randi(Nballs1)>54;
else S(n)=randi(Nballs2)>74; end, end
mean(S)
Alternately, we could use the randi discrete pseudorandom number generator to produce simulated observations:
S=[randi(Nballs1,[REPS/2 1])>54; randi(Nballs2,[REPS/2 1])>74];
mean(S)