## Documentation Center |

One-way analysis of variance

`p = anova1(X)p = anova1(X,group)p = anova1(X,group,`

`p = anova1(X)` performs
balanced one-way ANOVA for comparing the means of two or more columns
of data in the matrix `X`, where each column represents
an independent sample containing mutually independent observations.
The function returns the *p*-value under the null
hypothesis that all samples in `X` are drawn from
populations with the same mean.

If `p` is near zero, it casts doubt on the
null hypothesis and suggests that at least one sample mean is significantly
different than the other sample means. Common significance levels
are 0.05 or 0.01.

The `anova1` function displays two figures,
the standard ANOVA table and a box plot of the columns of `X`.

The standard ANOVA table divides the variability of the data into two parts:

Variability due to the differences among the column means (variability

*between*groups)Variability due to the differences between the data in each column and the column mean (variability

*within*groups)

The standard ANOVA table has six columns:

The source of the variability.

The degrees of freedom (

`df`) associated with each source.The mean squares (

`MS`) for each source, which is the ratio`SS/df`.The

*F*-statistic, which is the ratio of the mean squares.The

*p*-value, which is derived from the cdf of*F*.

The box plot of the columns of `X` suggests
the size of the *F*-statistic and the *p*-value.
Large differences in the center lines of the boxes correspond to large
values of *F* and correspondingly small values of *p*.

`anova1` treats `NaN` values
as missing, and disregards them.

`p = anova1(X,group)` performs
ANOVA by group. For more information on grouping variables, see Grouping Variables.

If `X` is a matrix, `anova1` treats
each column as a separate group, and evaluates whether the population
means of the columns are equal. This form of `anova1` is
appropriate when each group has the same number of elements (balanced
ANOVA). `group` can be a character array or a cell
array of strings, with one row per column of `X`,
containing group names. Enter an empty array (`[]`)
or omit this argument if you do not want to specify group names.

If `X` is a vector, `group` must
be a categorical variable, vector, string array, or cell array of
strings with one name for each element of `X`. `X` values
corresponding to the same value of `group` are placed
in the same group. This form of `anova1` is appropriate
when groups have different numbers of elements (unbalanced ANOVA).

If `group` contains empty or `NaN`-valued
cells or strings, the corresponding observations in `X` are
disregarded.

`p = anova1(X,group,displayopt)` enables
the ANOVA table and box plot displays when

`[p,table] = anova1(...)` returns
the ANOVA table (including column and row labels) in the cell array `table`.
Copy a text version of the ANOVA table to the clipboard using the `Copy
Text` item on the **Edit** menu.

`[p,table,stats] = anova1(...)` returns
a structure `stats` used to perform a follow-up multiple
comparison test. `anova1` evaluates the hypothesis
that the samples all have the same mean against the alternative that
the means are not all the same. Sometimes it is preferable to perform
a test to determine which pairs of means are significantly different,
and which are not. Use the `multcompare` function
to perform such tests by supplying the `stats` structure
as input.

The ANOVA test makes the following assumptions about the data
in `X`:

All sample populations are normally distributed.

All sample populations have equal variance.

All observations are mutually independent.

The ANOVA test is known to be robust with respect to modest violations of the first two assumptions.

`anova2` | `anovan` | `boxplot` | `manova1` | `multcompare`

Was this topic helpful?