%LMcs130202_4th.m
% Larsen & Marx (2006) Introduction to Mathematical Statistics 4th edition
% Case Study 13.2.1 Page 780-781
% Written by Eugene.Gallagher@umb.edu 12/3/2010; revised 2/15/11
% Calls other files

DATA=[13.8 11.7 14.0 12.6
12.9 16.7 15.5 13.8
25.9 29.8 27.8 25.0
18.0 23.1 23.0 16.9
15.2 20.2 19.0 13.7];
boxplot(DATA,'sym','r*','labels',...
{'Plain','Butter Vanilla','Roast Beef','Bread'});
figure(gcf);pause
plot(DATA');
ax1=gca;
set(ax1,'xtick',[1 2 3 4]);legend('1','2','3','4','5');
xlabel('Therapy');ylabel('HAT Score');
figure(gcf);pause
pause % Needed so can see the box plots
sumDATA=sum(DATA);
meanDATA=mean(DATA);
y=DATA(:);
% convert the data into columns;
g1=repmat(['S1';'S2';'S3';'S4';'S5'],4,1);
g2=[repmat('Pl',5,1);repmat('Bu',5,1);repmat('RB',5,1);repmat('Br',5,1)];
% find and delete any NaN elements, if any
i=~isnan(y);y=y(i);g1=g1(i,:);g2=g2(i,:);
[p,table,stats] = anovan(y,{g1 g2},'model','linear',...
    'varnames',{'Survey';'Flavor'});
[c,m,h] = multcompare(stats,'display','on','dimension',2);
figure(h)
title(' '),xlabel(' ');figure(gcf)
pause;

% Since the treatments were not replicated within blocks, Tukey's test
% for additivity should be run:
r1=repmat([1:5]',4,1);
r2=[repmat(1,5,1);repmat(2,5,1);repmat(3,5,1);repmat(4,5,1)];
X=[y r1 r2];
adTukeyAOV2(X,2,0.05)