www.gusucode.com > stats 源码程序 matlab案例代码 > stats/OneWayANOVAExample.m

    %% One-Way ANOVA
%%
% Create sample data matrix |y| with columns that are constants, plus random
% normal disturbances with mean 0 and standard deviation 1.

% Copyright 2015 The MathWorks, Inc.

y = meshgrid(1:5);
rng default; % For reproducibility
y = y + normrnd(0,1,5,5)
%%
% Perform one-way ANOVA.
p = anova1(y)
%%
% The ANOVA table shows the between-groups variation (|Columns|) and
% within-groups variation (|Error|). |SS| is the sum of squares, and |df|
% is the degrees of freedom. The total degrees of freedom is total number
% of observations minus one, which is 25 - 1 = 24. The between-groups
% degrees of freedom is number of groups minus one, which is 5 - 1 = 4. The
% within-groups degrees of freedom is total degrees of freedom minus the
% between groups degrees of freedom, which is 24 - 4 = 20.
%%
% |MS| is the mean squared error, which is |SS/df| for each source of
% variation. The _F_-statistic is the ratio of the mean squared errors
% (13.4309/2.2204). The _p_-value is the probability that the test
% statistic can take a value greater than or equal to the value of the test
% statistic, i.e., P(F > 6.05). The small _p_-value of 0.0023 indicates that
% differences between column means are significant.