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

    %% 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, respectively. The rows are popper types, oil and air. In the
% study, researchers popped a batch of each brand three times with each popper, that is, the
% number of replications is 3. The first three rows correspond to the oil
% popper, and the last three rows correspond to the air popper. The response
% values are the yield in cups of popped popcorn.
%%
% Perform a two-way ANOVA. Save the ANOVA table in the cell array |tbl| for
% easy access to results.
[p,tbl] = anova2(popcorn,3);
%%
% The column |Prob>F| shows the _p_-values for the three brands of popcorn
% (0.0000), the two popper types (0.0001), and the interaction between brand
% and popper type (0.7462). These values indicate that popcorn brand
% and popper type affect the yield of popcorn, but there is no evidence of
% an interaction effect of the two.
%%
% Display the cell array containing the ANOVA table.
tbl
%%
% Store the _F_-statistic for the factors and factor interaction in
% separate variables.
Fbrands = tbl{2,5}
Fpoppertype = tbl{3,5}
Finteraction = tbl{4,5}