
% Bone screws are the most commonly used type 
% of orthopedic implant.  Their precision is 
% critical and several dimensions are rigorously checked for
% conformity (outside and root diameters, pitch, tread angle).
% The screws are produced in lots of 20000.
% To confirm the homogeneity of production, 6 lots are selected
% and from each a sample of size 100 was obtained. 
% The following numbers of nonconforming screws are found in the six samples:
% 20, 17, 23, 9, 15, and 14.
% 
% Test the hypothesis of homogeneity of proportions of nonconforming
% screws in lots.

Xi =[24 17 23 9 15 14];
ni =[100 100 100 100 100 100];
pi = Xi./ni     %    0.24     0.17     0.23   0.09     0.15     0.14  
pbar = sum(Xi)/sum(ni)     %0.17
chi2 = sum(  (Xi - ni*pbar).^2./(ni * pbar * (1-pbar)) ) %11.4812 
pval = 1-chi2cdf(chi2, 6-1)  %0.0426 


 X=[];
for i=1:5
    for j = i+1:6
      X=[X;     i,j, abs(pi(i)-pi(j)), ...
          sqrt(chi2inv(1-0.05, 4-1)) * sqrt(  pi(i)* (1- pi(i))/ni(i) +   pi(j)* (1- pi(j))/ni(j)) , ...
          abs(pi(i)-pi(j)) > ...
          sqrt(chi2inv(1-0.05, 4-1)) * sqrt(  pi(i)* (1- pi(i))/ni(i) +   pi(j)* (1- pi(j))/ni(j)) ];   
    end
end
X
%         p(i)       p(j)         |p(i)-p(j)|    crit       different
%     1.0000    2.0000    0.0700    0.1590         0
%     1.0000    3.0000    0.0100    0.1676         0
%     1.0000    4.0000    0.1500    0.1437         1
%     1.0000    5.0000    0.0900    0.1556         0
%     1.0000    6.0000    0.1000    0.1538         0
%     2.0000    3.0000    0.0600    0.1577         0
%     2.0000    4.0000    0.0800    0.1320         0
%     2.0000    5.0000    0.0200    0.1449         0
%     2.0000    6.0000    0.0300    0.1430         0
%     3.0000    4.0000    0.1400    0.1423         0
%     3.0000    5.0000    0.0800    0.1543         0
%     3.0000    6.0000    0.0900    0.1525         0
%     4.0000    5.0000    0.0600    0.1279         0
%     4.0000    6.0000    0.0500    0.1257         0
%     5.0000    6.0000    0.0100    0.1392         0


