www.gusucode.com > stats 源码程序 matlab案例代码 > stats/MultipleComparisonOfMaterialStrengthExample.m
%% Multiple Comparisons for One-Way ANOVA %% % Input the sample data. % Copyright 2015 The MathWorks, Inc. strength = [82 86 79 83 84 85 86 87 74 82 ... 78 75 76 77 79 79 77 78 82 79]; alloy = {'st','st','st','st','st','st','st','st',... 'al1','al1','al1','al1','al1','al1',... 'al2','al2','al2','al2','al2','al2'}; %% % The data are from a study of the strength of structural beams in Hogg % (1987). The vector strength measures deflections of beams in thousandths % of an inch under 3000 pounds of force. The vector alloy identifies each % beam as steel (|st|), alloy 1 (|al1|), or alloy 2 (|al2|). % Although alloy is sorted in this example, grouping variables do not need % to be sorted. %% % Perform one-way ANOVA using |anova1|. Return the % structure |stats|, which contains the statistics <docid:stats_ug.bujc800 % multcompare> needs for performing <docid:stats_ug.bum2f3y-1 multiple % comparisons>. [~,~,stats] = anova1(strength,alloy); %% % The small _p_-value of 0.0002 suggests that the strength of the beams is % not the same. %% % Perform a multiple comparison of the mean strength of the beams. [c,~,~,gnames] = multcompare(stats); %% % Display the comparison results with the corresponding group names. [gnames(c(:,1)), gnames(c(:,2)), num2cell(c(:,3:6))] %% % The first two columns show the pair of 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 the 95% confidence % intervals of the true difference of means. The sixth column shows the _p_-value for a hypothesis % that the true difference of means for the corresponding groups is equal to zero. %% % The first two rows show that both comparisons involving the first group % (steel) have confidence intervals that do not include zero. Because the % corresponding _p_-values (1.6831e-04 and 0.0040, respectively) are % small, those differences are significant. %% % The third row shows that the differences in strength between the two % alloys is not significant. A 95% confidence interval for the difference % is [-5.6,1.6], so you cannot reject the hypothesis that the true % difference is zero. The corresponding _p_-value of 0.3560 in the sixth % column confirms this result. %% % In the figure, the blue bar represents the comparison interval for mean % material strength for steel. The red bars represent the comparison % intervals for the mean material strength for alloy 1 and alloy 2. Neither % of the red bars overlap with the blue bar, which indicates that the mean % material strength for steel is significantly different from that of alloy % 1 and alloy 2. To confirm the significant difference by clicking the bars % that represent alloy 1 and 2.