 
yijk=[...
9620  9590  9715  9690       9700  9710  9670  9695; ...
9670  9610  9675  9665       9680  9745  9720  9680; ...
9675  9685  9645  9710       9675  9665  9680  9730];
  
  a = 2;
  b = 4;
  n = 3;
  
  %matrices of means (y..., y_i.., y_ij.)
  yddd = mean(mean(yijk)) * ones(n, a*b)
  yijd = repmat(mean(yijk), n, 1)
  %yidd---------------------
      m=mean(yijk);
      mm=reshape(m', b, a);
      c=mean(mm);
      d=repmat(c',1,b);
      e=d';
  yidd = repmat(e(:)',n,1)

  
SST = sum(sum((yijk - yddd).^2) ) ;
SSA = sum(sum((yidd - yddd).^2) ) ;
SSB_A = sum(sum((yijd - yidd).^2) ) ;
SSE = sum(sum((yijk - yijd).^2) ) ;


MSA = SSA/(a-1)    ;
MSB_A = SSB_A/(a * (b-1)) ;
MSE = SSE/(a * b * (n-1)) ;


%A fixed B(A) random //// Or A random B(A) random
FArand = MSA/MSB_A  ;
pa = 1- fcdf(FArand, a-1, a*(b-1))  ;

% 
FB_A = MSB_A/MSE  %1.7725
pb_a =  1- fcdf(FB_A,  a*(b-1), a*b*(n-1))  ;

%Display bar a bar graph of anova table
H=figure;
set(H,'Position',[400 400 400 400]);
y=[0 0 1 1];
hold on
h1=fill([0 SST SST 0],y,'c');
y=y+1;
h2=fill([0 SSA SSA 0],y,'y');
h3=fill([0 SSB_A SSB_A 0]+SSA,y,'r');
h4=fill([0 SSE SSE 0]+SSA+SSB_A,y,'b');
hold off
legend([h2 h3 h4 h1],'SSA','SSB_A','SSE','SST','Location','SouthWest')
title('Sums of Squares')
axis tight

 
%Part (b)
X1=[...
9620  9590  9715  9690 ; ...
9670  9610  9675  9665 ; ...
9675  9685  9645  9710 ];
  
 
X2=[...
9700  9710  9670  9695; ...
9680  9745  9720  9680; ...
9675  9665  9680  9730];
  
x1b=mean(X1(:));x2b=mean(X2(:));
s1=std(X1(:));s2=std(X2(:));
sp = sqrt(  ((12-1)*s1^2 + (12-1)*s2^2)/22 )
t = (x1b - x2b)/(sp * sqrt(1/12 + 1/12))
p=2*tcdf(t, 22)