% LMcs120301_4th.m
% Larsen & Marx (2006) Introduction to Mathematical Statistics 4th edition
% Case Study 12.3.1 Page 749
% Written by Eugene.Gallagher@umb.edu 2/15/11
% There are at least 2 ways to analyze these data with Matlab & ANOVA
DATA=[29.6 27.3 5.8 21.6 29.2
    24.3 32.6  6.2 17.4 32.8
    28.5 30.8 11.0 18.3 25.0
    32.0 34.8  8.3 19.0 24.2]
Tdotj=sum(DATA)
Ymeandotj=mean(DATA)
[p,table,stats] = anova1(DATA);
pause % The pause is so that the boxplot can be examined before it is
      % overwritten by multcompare's graph
multcompare(stats,'ctype','hsd', 'alpha',0.05)
% ANOVA1 can only be used for balanced data,i.e., data with an equal number
% of cases per treatment level
% ANOVAN is the more
% general approach, but the data have to be restructured so that they are
% all in one column.
% This will be introduced later in the chapter
% multcompare(stats,'ctype','hsd')
y=DATA(:); % convert the data into columns
group=repmat(1:5,4,1);group=group(:);
[p,table,stats,terms] = anovan(y,group,'varnames','Among Antibiotics');
multcompare(stats,'ctype','hsd');