% LMex030504_4th
% Example 3.5.4 Page 178 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher@umb.edu for EEOS601
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% Revised 1/12/2011
% 50 patients are to be tested for a disease. Their blood samples are split
% into A and B pools. All of the A's are mixed together and tested. If the
% pooled A sample is negative, none of the patients have the disease. If
% the pooled A sample comes back positive, then all of the B samples must
% be tested. Under what conditions would this pooling strategy be more
% effective than testing all 50 samples?
% Use Matlab's minimization routine to find the exact number of tests
p=[logspace(-4,0,40)]';
EX=(1-p).^50+51*(1-(1-p).^50);
disp('      Table 3.5.1')
disp('      p        E(X)')
disp([p EX])
plot(p,EX);xlabel('Probability of Disease','FontSize',16)
ylabel('E(Number of Tests)','FontSize',16)
title('Example 3.5.4','FontSize',20)
figure(gcf);pause
% find the exact p value requiring 50 tests
PEx50 = fzero(@(p)(1-p).^50+51*(1-(1-p).^50)-50, 0.001, 0.999)
semilogx(p,EX);xlabel('Probability of Disease','FontSize',16)
ylabel('E(Number of Tests)','FontSize',16)
title('Example 3.5.4','FontSize',20)
hold on
% This plot simply puts a vertical line on the graph
semilogx([PEx50 PEx50],[0 50],'-.b','LineWidth',2);
% This plot simply puts a horizontal line on the graph
semilogx([1e-4 PEx50],[50 50],'-.b','LineWidth',2);
s=sprintf('%4.2f%% disease rate',PEx50*100)
text(PEx50+0.01,25,s,'FontSize',18)
hold off