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

  1.    stanvr(lcx,nt,nb,x,ft,fb,av)
  2.  
  3.       /* this function computes the analysis of variance table and   */
  4.       /* f-ratios for treatments and blocks of a randomized complete */
  5.       /* block design.                                               */
  6.  
  7.       int lcx,nb,nt;
  8.       float *ft,*fb,av[],x[];
  9.  
  10.    {
  11.       int i,ij,j;
  12.       float b,c,r,sumx,sumr2,sumc2,t;
  13.  
  14.       sumx = 0.;
  15.       av[0] = 0.;
  16.       sumr2 = 0.;
  17.       sumc2 = 0.;
  18.  
  19.       for(i = 0; i<= nb-1; i++)
  20.       {
  21.        r = 0.;
  22.        ij = i * lcx;
  23.  
  24.        for(j = 0; j <= nt-1; j++)
  25.        {
  26.         av[0] = av[0] + x[ij] * x[ij];
  27.         r = r + x[ij];
  28.         ij = ij + 1;
  29.        }
  30.        sumx = sumx + r;
  31.        sumr2 = sumr2 + r * r;
  32.       }
  33.  
  34.       for(i = 0; i <= nt-1; i++)
  35.       {
  36.        c = 0.;
  37.        ij = i;
  38.  
  39.        for(j = 0; j <= nb-1; j++)
  40.        {
  41.        ij = i + (j * lcx);
  42.        c = c + x[ij];
  43.        }
  44.        sumc2 = sumc2 + c * c;
  45.       }
  46.       av[1] = nb * nt;
  47.       av[2] = sumx * sumx / av[1];
  48.       av[3] = 1.;
  49.       av[4] = sumc2 / nb - av[2];
  50.       av[5] = nt - 1;
  51.       av[6] = av[4] / av[5];
  52.       av[7] = sumr2 / nt - av[2];
  53.       av[8] = nb - 1;
  54.       av[9] = av[7] / av[8];
  55.       av[10] = av[0] - av[7] - av[4] - av[2];
  56.       av[11] = av[5] * av[8];
  57.       av[12] = av[10] / av[11];
  58.       *ft = av[4] / (av[5] * av[12]);
  59.       *fb = av[7] / (av[8] * av[12]);
  60.    }
  61.