% LMex020402_4th.m
% Example 2.4.2 The two-boys problem page 44 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher@umb.edu 1/14/11 30 (with advanced problem,
% analyzing the problem as a Monte Carlo simulation)
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% Consider the set of families with 2 children. What is the probability
% that both children are boys, given that at least one child is a boy?
% Use LMex020201_4th.m as a model
gender=['B';'G']
% create the sample space
births=2;
S=repmat(' ',2^births,2);
i=1;
for birth1=1:2
for birth2=1:2
S(i,:)=[gender(birth1) gender(birth2)];
i=i+1;
end
end
disp('The sample space, S:')
S
% Event A=both children are boys, Event B=at least one child is a boy.
% P(A|B)=P(A^B)/P(B)=P(A)/P(B);
[r,c]=size(S);
PA=sum(sum(S'=='B')==2)/r
PB=sum(sum(S'=='B')~=0)/r
fprintf('The probability that A, "both of two children are boys", \n')
fprintf('given B "that at least one child is a boy" is PA/PB = %6.4f\n',...
PA/PB)