anova1
statistics: p = anova1 (x)
statistics: p = anova1 (x, group)
statistics: p = anova1 (x, group, displayopt)
statistics: p = anova1 (x, group, displayopt, vartype)
statistics: [p, atab] = anova1 (x, …)
statistics: [p, atab, stats] = anova1 (x, …)
Perform a one-way analysis of variance (ANOVA) for comparing the means of two
or more groups of data under the null hypothesis that the groups are drawn
from distributions with the same mean. For planned contrasts and/or
diagnostic plots, use anovan instead.
anova1 can take up to three input arguments:
vartype is 'equal' the variances are assumed to be equal
(this is the default). When vartype is 'unequal' the
population variances are not assumed to be equal and Welch’s ANOVA test is
used instead.
vartype is an Octave extension: MATLAB’s anova1 takes no
fourth argument. It does not error on one either, it accepts it and
ignores it, returning the same p and F for 'unequal'
as for 'equal'. Code written against this function and then run
in MATLAB therefore gets the classic ANOVA silently, with no diagnostic
of any kind. Note that anova2’s analogous fourth argument does
make MATLAB error, so the silence here is particular to anova1.
anova1 can return up to three output arguments:
A categorical group may declare levels that no observation uses.
Such a level takes no part in the analysis and is dropped from every field
of stats, so n, means and gnames always describe
the same groups, in the same order, and can be indexed together.
This is a deliberate deviation from MATLAB, which drops an unused level
from gnames but keeps it in n and means as a count of
zero and a mean of NaN. Those fields then disagree in length and
the group indices run past gnames, so MATLAB’s own multcompare
reports comparisons against a group holding no observations and labels them
with indices that its gnames cannot resolve.
If anova1 is called without any output arguments, then it prints the results in a one-way ANOVA table to the standard output. It is also printed when displayopt is ’on’.
Examples:
x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); anova1 (x, [], 'off'); [p, atab] = anova1(x); |
x = ones (50, 4) .* [-2, 0, 1, 5];
x = x + normrnd (0, 2, 50, 4);
groups = {"A", "B", "C", "D"};
anova1 (x, groups);
|
See also: anova2, anovan, multcompare
Source Code: anova1
rng (42); x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); anova1 (x, [], 'off');
ANOVA Table
Source SS df MS F Prob>F
------------------------------------------------------
Groups 111.9398 5 22.3880 18.42 0.0000
Error 36.4629 30 1.2154
Total 148.4027 35
rng (42); x = meshgrid (1:6); x = x + normrnd (0, 1, 6, 6); [p, atab] = anova1 (x);
ANOVA Table
Source SS df MS F Prob>F
------------------------------------------------------
Groups 111.9398 5 22.3880 18.42 0.0000
Error 36.4629 30 1.2154
Total 148.4027 35
rng (42);
x = ones (50, 4) .* [-2, 0, 1, 5];
x = x + normrnd (0, 2, 50, 4);
groups = {'A', 'B', 'C', 'D'};
anova1 (x, groups);
ANOVA Table
Source SS df MS F Prob>F
------------------------------------------------------
Groups 1037.3570 3 345.7857 81.63 0.0000
Error 830.2136 196 4.2358
Total 1867.5706 199
y = [54 87 45; 23 98 39; 45 64 51; 54 77 49; 45 89 50; 47 NaN 55]; g = [1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ]; anova1 (y(:), g(:), 'on', 'unequal');
Welch's ANOVA Table
Source F df dfe Prob>F
-----------------------------------------
Groups 15.52 2 7.58 0.0021