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

  1.    stanvb(lcx,lcn,nb,nt,ntb,nr,n,x,f,av,g)
  2.  
  3.       /* this function produces the analysis of variance table n and
  4.          the f-ratio for treatments of a square, balanced, incomplete
  5.          block design. the sum of squares is adjusted because of
  6.          incompleteness.
  7.        */
  8.  
  9.       int lcn,lcx,n[],nb,nt,ntb,nr;
  10.       float *f,av[],g[],x[];
  11.  
  12.    {
  13.       int i,j,ijx,ijn,klrn,klrx;
  14.       float an,den,p,s,w,w1,ww1,xb,xl,xn,xt,xtb,xr,xnum,u;
  15.  
  16.       xb = nb;
  17.       xt = nt;
  18.       xtb = ntb;
  19.       xr = nr;
  20.       xnum = nr * (ntb - 1);
  21.       den = nt - 1;
  22.       xl = xnum / den;
  23.       u = 0.;
  24.       w1 = 0.;
  25.       av[0] = 0.;
  26.  
  27.       for(i = 0; i <= nb-1; i++)
  28.       {
  29.        ww1 = 0.;
  30.        ijx = i * lcx;
  31.        ijn = i * lcn;
  32.  
  33.        for(j = 0; j <= nt -1; j++)
  34.        {
  35.         an = n[ijn];
  36.         x[ijx] = x[ijx] * an;
  37.         av[0] = av[0] + x[ijx] * x[ijx];
  38.         ww1 = ww1 + x[ijx];
  39.         ijn = ijn + 1;
  40.         ijx = ijx + 1;
  41.        }
  42.        u = u + ww1;
  43.        g[i] = ww1;
  44.        w1 = w1 + ww1 * ww1;
  45.       }
  46.       av[2] = u * u / (xb * xtb);
  47.       av[7] = w1 / xtb - av[2];
  48.       w = 0.;
  49.       klrn = 0;
  50.       klrx = 0;
  51.  
  52.       for(j = 0; j <= nt-1; j++)
  53.       {
  54.        s = 0.;
  55.        p = 0.;
  56.  
  57.        for(i = 0; i <= nb-1; i++)
  58.        {
  59.         ijn = klrn + i * lcn;
  60.         ijx = klrx + i * lcx;
  61.         xn = n[ijn];
  62.         p = p + xn * g[i];
  63.         s = s + x[ijx];
  64.        }
  65.        w = w + (xtb * s - p) * (xtb * s - p);
  66.        klrn = klrn + 1;
  67.        klrx = klrx + 1;
  68.       }
  69.       av[4] = w / (xtb * xt * xl);
  70.       av[3] = 1.;
  71.       av[5] = nt - 1;
  72.       av[8] = nb - 1;
  73.       av[10] = av[0] - av[7] - av[4] - av[2];
  74.       av[1] = nb * ntb;
  75.       av[11] = av[1] - av[8] -av[5] - 1.;
  76.       av[6] = av[4] / av[5];
  77.       av[9] = 9999.9999;
  78.       av[12] = av[10] / av[11];
  79.       *f = av[4] * av[11] / (av[5] * av[10]);
  80.    }
  81.