home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / STMEDT.C < prev    next >
Encoding:
Text File  |  1984-08-03  |  1006 b   |  50 lines

  1.       stmedt(m,a,n,b,chi2)
  2.  
  3.       /*this subroutine compares two groups of data using the median*/
  4.       /*test and computes the chi square value of the 2 by 2 table*/
  5.       /*on 1 degree of freedom*/
  6.  
  7.       float a[1], b[1],*chi2;
  8.       int m,n;
  9.  
  10.      {
  11.  
  12.       float em,en,xm1,xm,z,zz;
  13.       int i,j,k,m1,m2;
  14.       extern double fabs();
  15.  
  16.       em = m;
  17.       en = n;
  18.       m1 = m + n;
  19.       xm1 = m1;
  20.       m2 = m1/2;
  21.       xm = xm1*0.5;
  22.       sort (a,m);
  23.       sort (b,n);
  24.       i = 1;
  25.       j = 1;
  26.  
  27.       for (k = 1; k <= m2; k++)
  28.       {
  29.         if (a[i-1] >  b[j-1])
  30.         {
  31.           j = j + 1;
  32.           if (j <= n) goto l20;
  33.           z = en*(xm - en - em);
  34.           goto l30;
  35.         }
  36.         else
  37.         {
  38.           i = i + 1;
  39.           if (i <= m) goto l20;
  40.           z = em*(en + em - xm);
  41.           goto l30;
  42.         }
  43. l20:  ;
  44.       }
  45.       z = (i - 1)*en - (j - 1)*em;
  46. l30:  zz = fabs(z) - xm;
  47.       *chi2 = 2.0*zz*zz/(em*en*xm);
  48.  
  49.      }
  50.