/* Appendix 2                                              */

/* Functionally, these modified IML modules are the same   */
/* as the original modules(*) except for the addition of   */
/* the randomization test to test for differences between  */
/* to test for differences between the means of two        */
/* independent samples. An example that illustrates the    */
/* use of the PERMTEST module for this addition is shown   */
/* at the end of the Appendix.                             */
/*                                                         */
/* (*) See "A PROC IML Program to obtain Exact             */
/* Significance Levels in the Nonparametric                */
/* Two-Independent-Samples: Location Problem" in           */
/* Observations, Fourth Quarter 1993.                      */

proc iml;

   /*          The Choose Module                           */
   /* We consider all the possible choices of M objects    */
   /* from a set of M+N. There is a sequential way of      */
   /* ordering them. The module CHOOSE gives you the next  */
   /* choice when you supply a given selection and the     */
   /* parameters M and N.  The vector VEC is input and     */
   /* consists of integers from 1 to M+N. Examples if you  */
   /* are chosing five objects from a set of 8:            */
   /* 1) Input mvec0=[1 2 3 5 7] and get mvec1=[1 2 3 5 8] */
   /* 2) Input mvec0=[1 3 4 7 8] and get mvec1=[1 3 5 6 7] */
   /* This module is used inside the module PERMTEST.      */

start choose(vec,mvec0,m,n, mvec1);
mvec1=mvec0;
do place=m to 1 by -1;
   if mvec0[1,place](mn+1)/2);
   if test='VW' then score0=probit(mvec0/(mn+1));
   if test='SAVAGE' then do;
      score0=j(1,m,.);
      do j = 1 to m;
         mj=mvec0[1,j];
         score0[1,j]=sum(savvec[1,1:mj])-1;
       end;
   end;
   if test='MEAN' then score0=yvec[mvec0,];
   rankstat=sum(score0);
   if rankstat<=sumscore then pval[1,1]=pval[1,1]+1;
   if rankstat>=sumscore then pval[1,2]=pval[1,2]+1;
   if test='MEAN' then do;
      if abs(mn#rankstat-m#ysum)>=abs(mn#sumscore-m#ysum)
      then pval[1,3]=pval[1,3]+1;
   end;
   if i1 then pval[1,3]=1;
reset noname;
chead={"Lower-Tail" "Upper-Tail" "Two-Tail"};
print pval[colname=chead];
finish;


   /* For Example 2                                        */
   /* Use 'Mean' for Test                                  */
   /* M=4 N=6                                              */
   /* SUMSCORE = Sum of Y's from sample 1 = 50.8           */
yvec={12.6 14.4 12.3 11.4 8.3 12.6 8.4 11.5 10.3 6.2}`;
run permtest('mean',4,6,50.8,yvec, pval);