% LMex020414_4th.m
% Example 2.4.14 Bayes theorem & cancer screening p 65-66 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene Gallagher 2001
% Eugene.Gallagher@umb.edu
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% Revised 1/15/2011
% Application of Bayes theorem
% PA_1       = Probability of cancer in population = Prevalence Rate
% PA_2       = 1-PA_1=Probability that patient is cancer-free
% PB         = Test is positive for cancer
% PBgivenA1  = 0.90  = Sensitivity of the test
% PBgivenA2  = 0.001 = False Positive Frequency
% PBcgivenA1 = False Negative Frequency
% PBcgivenA2 = Screened negative and did not have the disease = Specificity
% Bayes Theorem for a test's yield or predictive value
% Yield = Predictive Value = (Prevalence)*(Sensitivity)/
%                (Prevalence)*(Sensitivity)+ (1-Prevalence)*(1-Sensitivity)                    
PA_1=0.0001
PA_2=1-PA_1
PBgivenA1=0.90
% False positive rate:
PBgivenA2=0.001
PA1givenB=PBgivenA1*PA_1/(PBgivenA1*PA_1+PBgivenA2*PA_2)
disp('              Table 2.4.3')
disp('    P(A_1)   P(B|A_1^c) P(A_1|B)')
disp('    Disease   False    Predictive')
disp('  Prevalence Positive  Value (Yield)')
for PA_1=logspace(-4,-2,3)
    for PBgivenA2=logspace(-3,-4,2)
        PA1givenB=PBgivenA1*PA_1/(PBgivenA1*PA_1+PBgivenA2*PA_2);
        disp([PA_1 PBgivenA2 PA1givenB]);
    end
end
