www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TwoWayANOVAMultipleComparisonsExample.m
%% Multiple Comparisons for Two-Way ANOVA % Load the sample data. % Copyright 2015 The MathWorks, Inc. load popcorn popcorn %% % The data is from a study of popcorn brands and popper types (Hogg 1987). % The columns of the matrix |popcorn| are brands (Gourmet, National, and % Generic). The rows are popper types oil and air. In the study, % researchers popped a batch of each brand three times with each popper. % The values are the yield in cups of popped popcorn. %% % Perform a two-way ANOVA. Also compute the statistics that you need to % perform a multiple comparison test on the main effects. [~,~,stats] = anova2(popcorn,3,'off') %% % The |stats| structure includes % % * The mean squared error (|sigmasq|) % * The estimates of the mean yield for each popcorn brand (|colmeans|) % * The number of observations for each popcorn brand (|coln|) % * The estimate of the mean yield for each popper type (|rowmeans|) % * The number of observations for each popper type (|rown|) % * The number of interactions (|inter|) % * The _p_-value that shows the significance level of the interaction term (|pval|) % * The error degrees of freedom (|df|). %% % Perform a multiple comparison test to see if the popcorn yield differs % between pairs of popcorn brands (columns). c = multcompare(stats) %% % The first two columns of |c| show the groups that are compared. The % fourth column shows the difference between the estimated group means. The third and % fifth columns show the lower and upper limits for 95% confidence % intervals for the true mean difference. The sixth column contains the _p_-value for a % hypothesis test that the corresponding mean difference is equal to zero. All % _p_-values (0, 0, and 0.0116) are very small, which indicates that the % popcorn yield differs across all three brands. %% % The figure shows the multiple comparison of the means. By default, the % group 1 mean is highlighted and the comparison interval is in blue. % Because the comparison intervals for the other two groups do not % intersect with the intervals for the group 1 mean, they are highlighted % in red. This lack of intersection indicates that both means are different % than group 1 mean. Select other group means to confirm % that all group means are significantly different from each other. %% % Perform a multiple comparison test to see the popcorn yield differs % between the two popper types (rows). c = multcompare(stats,'Estimate','row') %% % The small _p_-value of 0.0001 indicates that the popcorn yield differs % between the two popper types (air and oil). The figure shows the same % results. The disjoint comparison intervals indicate that the group means are significantly % different from each other.