home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / STANVL.C < prev    next >
Encoding:
Text File  |  1984-08-19  |  1.6 KB  |  68 lines

  1.    stanvl(lcd,lcm,n,m,d,ans,t)
  2.  
  3.       /* this function computes the analysis of variance table      */
  4.       /* for a simple latin square design.                          */
  5.  
  6.       int lcd,lcm,m[],n;
  7.       float ans[],d[],t[];
  8.  
  9.    {
  10.       int i,ijd,ijm,j,ji,k,klrd;
  11.       float anst,c,r,sumx,sumx2,sumc2,sumr2,sumt,sumt2,xn;
  12.  
  13.       for(i = 0; i <= n-1; i++)
  14.        t[i] = 0.;
  15.       sumx = 0.;
  16.       sumx2 = 0.;
  17.       sumc2 = 0.;
  18.       sumr2 = 0.;
  19.       klrd = 0;
  20.  
  21.       for( i = 0; i <= n-1; i++)
  22.       {
  23.        r = 0.;
  24.        c = 0.;
  25.        ijd = i * lcd;
  26.        ijm = i * lcm;
  27.  
  28.        for(j = 0; j <= n-1; j++)
  29.        {
  30.         ji = klrd + j * lcd;
  31.         sumx = sumx + d[ijd];
  32.         sumx2 = sumx2 + d[ijd] * d[ijd];
  33.         c = c + d[ji];
  34.         k = m[ijm];
  35.         t[k-1] = t[k-1] + d[ijd];
  36.         r = r + d[ijd];
  37.         ijd = ijd + 1;
  38.         ijm = ijm + 1;
  39.        }
  40.        klrd = klrd + 1;
  41.        sumc2 = sumc2 + c * c;
  42.        sumr2 = sumr2 + r * r;
  43.       }
  44.       sumt2 = 0.;
  45.  
  46.       for(i = 0; i <= n-1; i++)
  47.        sumt2 = sumt2 + t[i] * t[i];
  48.       xn = n;
  49.       c = sumx * sumx / (xn * xn);
  50.       ans[0] = sumr2 / xn - c;
  51.       ans[4] = sumc2 / xn - c;
  52.       ans[8] = sumt2 / xn - c;
  53.       ans[1] = n - 1;
  54.       ans[2] = ans[0] / ans[1];
  55.       ans[13] = ans[1] * (xn - 2.);
  56.       ans[12] = sumx2 - c - ans[0] - ans[4] - ans[8];
  57.       ans[14] = ans[12] / ans[13];
  58.       ans[6] = ans[4] / ans[1];
  59.       ans[10] = ans[8] / ans[1];
  60.       anst = ans[1] * ans[14];
  61.       ans[3] = ans[0] / anst;
  62.       ans [7] = ans[4] / anst;
  63.       ans[11] = ans[8] / anst;
  64.       ans[5] = ans[1];
  65.       ans[9] = ans[1];
  66.    }
  67.  
  68.