% LMex020412_4th.m
% Example 2.4.14 Bayes theorem  p 63-64 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher@umb.edu, revised 1/15/11
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% Application of Bayes theorem
% A_1       = Coin Came up heads, chip came from urn 1
% A_2       = Coin came up tails, chip came from urn 2
% B         = white chip is drawn
PA1        = 2/3;
PA2        =1-PA1;
PBgivenA1  = 3/7;
PBgivenA2  = 6/9;
% PA2B= Probability of Tails given that the chip was white.
PA2B=PBgivenA2*PA2/(PBgivenA2*PA2+PBgivenA1*PA1);
fprintf('The probability that the coin toss was tails is %6.4f.\n',PA2B)
format rat
disp(PA2B)
format
% Note that the equation could be modified if there were 3 or more
% partitions:
% PA3B=PBgivenA3*PA3/(PBgivenA3*PA3+PBgivenA2*PA2+PBgivenA1*PA1);