clear all
close all
  disp('C677T')
  set(0, 'DefaultAxesFontSize', 16);
  lw =2.5;  fs = 16;  msize = 10;



k = 3 %3 groups
n1 = 312;  n2 = 378; n3 = 125; n=n1+n2+n3;

% (i) Homocysteine, ìmol/l 
 X1bar = 14.1;  s1 = 1.9;
 X2bar = 14.2;  s2 = 2.3;
 X3bar = 15.3;  s3 = 3.0;
Xbarbar = (X1bar + X2bar + X3bar)/k;
varbetween = 1/(k-1) * (n1 * (X1bar - Xbarbar)^2  + ...
    n2 * (X2bar - Xbarbar)^2 + n3 * (X3bar - Xbarbar)^2); 
varwithin  = 1/(n1 + n2 + n3 - 3) * ((n1-1)*s1^2 + ...
    (n2 -1) * s2^2 + (n3-1) * s3^2);

F1 = varbetween/varwithin ;  %is F with k-1 and n-k df.
p1 = 1-Fcdf(F1, k-1, n-k)  %7.8493e-008


% (ii) Red blood cell folate, nmol/l 
 Y1bar = 715;  s1 = 258;
 Y2bar = 661;  s2 = 236;
 Y3bar = 750;  s3 = 348;
Ybarbar = (Y1bar + Y2bar + Y3bar)/k;
varbetween = 1/(k-1) * (n1 * (Y1bar - Ybarbar)^2  + ...
    n2 * (Y2bar - Ybarbar)^2 + n3 * (Y3bar - Ybarbar)^2); 
varwithin  = 1/(n1 + n2 + n3 - 3) * ((n1-1)*s1^2 + ...
    (n2 -1) * s2^2 + (n3-1) * s3^2);

F2 = varbetween/varwithin ;  %is F with k-1 and n-k df.
p2 = 1-Fcdf(F2, k-1, n-k)  %4.5595e-004



% (iii) Serum folate, nmol/l 
 Z1bar = 13.1;  s1 = 4.7;
 Z2bar = 12.3;  s2 = 4.2;
 Z3bar = 11.4;  s3 = 4.4;
%  &   13.1 (4.7) & 12.3 (4.2) & 11.4 (4.4)\\
% Red blood cell folate, nmol/l &   715 (258) & 661 (236) & 750 (348)\\
Zbarbar = (Z1bar + Z2bar + Z3bar)/k;
varbetween = 1/(k-1) * (n1 * (Z1bar - Zbarbar)^2  + ...
    n2 * (Z2bar - Zbarbar)^2 + n3 * (Z3bar - Zbarbar)^2); 
varwithin  = 1/(n1 + n2 + n3 - 3) * ((n1-1)*s1^2 + ...
    (n2 -1) * s2^2 + (n3-1) * s3^2);

F3 = varbetween/varwithin ;  %is F with k-1 and n-k df.
p3 = 1-Fcdf(F3, k-1, n-k) %3.8829e-004


%--------------------------------------------


% (iii) Serum folate, nmol/l 
 Z1bar = 13.1;  s1 = 4.7;
 Z2bar = 12.3;  s2 = 4.2;
 Z3bar = 11.4;  s3 = 4.4;
%  &   13.1 (4.7) & 12.3 (4.2) & 11.4 (4.4)\\
% Red blood cell folate, nmol/l &   715 (258) & 661 (236) & 750 (348)\\
Zbarbar = (Z1bar + Z2bar + Z3bar)/k   %12.2667
varbetween = 1/(k-1) * (n1 * (Z1bar - Zbarbar)^2  + ...
    n2 * (Z2bar - Zbarbar)^2 + n3 * (Z3bar - Zbarbar)^2) %7.9302 
varwithin  = 1/(n1 + n2 + n3 - 3) * ((n1-1)*s1^2 + ...
    (n2 -1) * s2^2 + (n3-1) * s3^2) %3.8829e-004


F3 = varbetween/varwithin  %is F with k-1 and n-k df.
p3 = 1-Fcdf(F3, k-1, n-k)

% (ii) Red blood cell folate, nmol/l 
 Y1bar = 715;  s1 = 258;
 Y2bar = 661;  s2 = 236;
 Y3bar = 750;  s3 = 348;
Ybarbar = (Y1bar + Y2bar + Y3bar)/k  %708.6667
varbetween = 1/(k-1) * (n1 * (Y1bar - Ybarbar)^2  + ...
    n2 * (Y2bar - Ybarbar)^2 + n3 * (Y3bar - Ybarbar)^2)  %5.4246e+005 
varwithin  = 1/(n1 + n2 + n3 - 3) * ((n1-1)*s1^2 + ...
    (n2 -1) * s2^2 + (n3-1) * s3^2)  %6.9847e+004

F2 = varbetween/varwithin   %7.7665
p2 = 1-Fcdf(F2, k-1, n-k) %4.5595e-004

