Two-Stage Dorfman Screening

 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: IEDORF2                                             */
 /*   TITLE: Two-Stage Dorfman Screening                         */
 /* PRODUCT: QC                                                  */
 /*  SYSTEM: ALL                                                 */
 /*    KEYS: Inspection Sampling,                                */
 /*   PROCS: TABULATE                                            */
 /*    DATA:                                                     */
 /*                                                              */
 /*    MISC:                                                     */
 /*                                                              */
 /*   NOTES: This program tabulates measures of effectiveness    */
 /*          for two-stage Dorfman screening of an infinite lot  */
 /*          under an imperfect inspection model.                */
 /*                                                              */
 /*          Notation:                                           */
 /*                                                              */
 /*          omega   = proportion of nonconforming (defective)   */
 /*                    items in lot                              */
 /*                                                              */
 /*          n0      = number of items in initial group          */
 /*          n1      = number of items in second group           */
 /*                                                              */
 /*          p0      = Pr[ for initial group, declare NC | at    */
 /*                        least one NC item ]                   */
 /*          p0prime = Pr[ for initial group, declare NC | no    */
 /*                        NC items ]                            */
 /*                                                              */
 /*          p1      = Pr[ for first subgroup,  declare NC | at  */
 /*                        least one NC item ]                   */
 /*          p1prime = Pr[ for first subgroup, declare NC | no   */
 /*                        NC items ]                            */
 /*                                                              */
 /*          pcnc    = Pr[ correct classification of defective   */
 /*                        (nonconforming) item ]                */
 /*                                                              */
 /*          pcc     = Pr[ correctly classifying conforming      */
 /*                        item ]                                */
 /*                                                              */
 /*          EPR     = pct reduction in expected number of tests */
 /*                                                              */
 /*     Comment by RNR on 13SEP91:                               */
 /*     It appears that the values of EPR in Table 2 of Kotz     */
 /*     and Johnson (1982) are in error (these values were       */
 /*     reprinted in Table 7 of Johnson et al. (1987)).  This    */
 /*     program computes EPR using equations published in two    */
 /*     different references (see below), and the results are    */
 /*     in agreement.                                            */
 /*                                                              */
 /*                                                              */
 /*     REF: Johnson, N. L., Kotz, S., and Rodriguez, R. N.      */
 /*          (1987), Statistical Effects of Imperfect Inspection */
 /*          Sampling:  III. Screening (Group Testing), Journal  */
 /*          of Quality Technology 20, 98-124.  See Table 8.     */
 /*                                                              */
 /*          Johnson, N. L., Kotz, S., and Wu, X. (1991).        */
 /*          Inspection Errors for Attributes in Quality         */
 /*          Control.  London:  Chapman & Hall.  See Chapter 6.  */
 /*                                                              */
 /*          Kotz, S. and Johnson, N. L. (1982), Errors in       */
 /*          Inspection and Grading:  Distributional Aspects of  */
 /*          Screening and Hierarchal Screening, Communications  */
 /*          in Statistics--Theory and Methods 11(18), 1997-     */
 /*          2016.                                               */
 /*                                                              */
 /*                                                              */
 /****************************************************************/

data table;

   keep omega n0 n1 p0 p1 p2 p0prime p1prime p2prime
        pcc pcnc book  kj82 ;

   label omega   = 'omega'

         n0      = 'n0'
         n1      = 'n1'

         p0      = 'p0'
         p1      = 'p1'
         p2      = 'p'

         p0prime = 'p0'''
         p1prime = 'p1'''
         p2prime = 'p'''

         pcc     = 'PC(C)'
         pcnc    = 'PC(NC)'

         book    = 'JKW91 EPR'
         kj82    = 'KJ82 EPR'  ;

   format pcc 6.4 pcnc 6.4 book kj82 4.1 ;

   input n0 n1 @;

   /*--- find hi---*/
   h1 = n0 / n1;

   /*---additional parameters---*/
   omega   = 0.05;

   p0      = 0.98;
   p1      = 0.98;
   p2      = 0.98;

   p0prime = 0.05;
   p1prime = 0.05;
   p2prime = 0.05;

   /*---find pcnc = Pr[ correct given nc ]---*/
   pcnc = p0 * p1 * p2 ;

   /*---evaluate p0*(n) and p0(n) for n = n0, n1---*/
   p0starn0 = (1 - omega) ** ( n0 - 1 );
   p0starn1 = (1 - omega) ** ( n1 - 1 );
   p0n0     = (1 - omega) ** n0 ;
   p0n1     = (1 - omega) ** n1 ;

   /*---find pcc---*/
   term1 = p0starn0 * p0prime * p1prime * p2prime ;
   term2 = ( p0starn1 - p0starn0 ) *
           p0 * p1prime * p2prime ;
   term3 = ( 1 - p0starn1 ) * p0 * p1 * p2prime ;
   pcc   = 1 - ( term1 + term2 + term3 );

   /*---preliminary work for expected percent reduction---*/
   pi0 = 1;
   pi1 = p0n0 * p0prime + ( 1 - p0n0 ) * p0 ;
   pi2 = p0n0 * p0prime * p1prime +
         ( p0n1 - p0n0 ) * p0 * p1prime +
         ( 1 - p0n1    ) * p0 * p1 ;
   h2  = n1;

   /*---using equation (6.19) on page 88 of JKW---*/
   term0 = pi0 / ( h1 * h2 );
   term1 = pi1 / h2 ;
   term2 = pi2 ;
   en0   = term0 + term1 + term2;
   book  = 100 * ( 1 - en0 );

   /*---using equation (21.4) of Kotz and Johnson (1982)---*/
   psub1 = p0n0 * ( p0 - p0prime );
   psub2 = p0n1 * ( p1 - p1prime );
   epr = 1 - ( 1 / n0 )
         - ( p0 * p1 )
         - ( p0 - psub1 ) / n1
         + psub1 * p1prime
         + psub2 * p0 ;
   kj82 = epr * 100 ;

   /*---output observation---*/
   output;

cards;
6     2
6     3
12    2
12    3
12    4
12    6
run;

proc sort data=table;
   by omega p0 p1 p2 p0prime p1prime p2prime ;

proc print label noobs;
   by omega p0 p1 p2 p0prime p1prime p2prime ;
   var n0 n1 pcnc pcc book kj82 ;
run;