% Blocking by Rats.
%
% A biologist wishes to determine whether or not four different
% testing procedures result in different responses on a concentration
% of particular poisson in blood of experimental rats.
% To minimize the influence of rat-to-rat variability, the
% biologist selects only four rats.
% Each of four rats is given the same dose of poisson per gr of body weight
% and samples of their blood tested by the four testing methods
% administered in random order.
% DATA
% concentration              procedure            rat
% ----------------------------------------------------
%  9.3                            1                 1
%  9.4                            2                 1
%  9.2                            3                 1
%  9.7                            4                 1
%  9.4                            1                 2
% . . . 
% 10.2                            4                 4
%
% Correct -- Use RAT as a block
clear all
close all
  disp('Blocking by Rats')
  set(0, 'DefaultAxesFontSize', 16);
  lw =2.5;  fs = 16;  msize = 10;



concentration = [9.3 9.4 9.2 9.7 9.4 9.3 9.4 9.6 ...
                        9.6 9.8 9.5 10.0 10.0 9.9 9.7 10.2];
procedure =        [1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4];
rat =              [1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4];
[p,table,stats,terms]=anovan(concentration,{procedure,rat},...
 'model','interaction', 'varnames',{'procedure','rat'})
%%
%p = 1.0e-003 * 0.8713
%    0.0452
%
%table =
%   'Source'    'Sum Sq.'  'd.f.'  'Singular?' 'Mean Sq.'
%   'X1'        [0.3850]    [ 3]    [    0]    [ 0.1283]
%   'X2'        [0.8250]    [ 3]    [    0]    [ 0.2750]
%   'Error'     [0.0800]    [ 9]    [    0]    [ 0.0089]
%   'Total'     [1.2900]    [15]    [    0]           []
%
%   'F'          'Prob>F'
%   [14.4375]    [8.7127e-004]
%   [30.9375]    [4.5233e-005]
%          []               []
%          []               []



% BAD Approach

 [p,table,stats,terms] = anovan(concentration,{procedure}, ...
'varnames',{'procedure'})

%p = 0.2196
%
%table =
%  'Source'   'Sum Sq.'   'd.f.'   'Singular?'   'Mean Sq.'
%  'X1'       [ 0.3850]   [   3]   [        0]   [  0.1283]
%  'Error'    [ 0.9050]   [  12]   [        0]   [  0.0754]
%  'Total'    [ 1.2900]   [  15]   [        0]           []
%
%  'F'       'Prob>F'
%  [1.7017]  [0.2196]
%  []              []
%  []              []