Interactive plot of multiple comparisons of means for analysis of variance (ANOVA)
To a close approximation, the difference between two mean estimates is statistically significant if their comparison intervals are disjoint, and is not statistically significant if their comparison intervals overlap. You can click an estimate to display its mean and comparison interval in blue, statistically different means and comparison intervals in red, and statistically similar means and comparison intervals in gray.
plotComparisons( plots into
ax using any of the input argument combinations in the
specifies additional options using one or more name-value arguments. For example, you can
specify the confidence level for the bounds of the comparison interval.
f = plotComparisons(___)
f to query
or modify properties of the figure after it is created.
Compare Group Means of One-Way ANOVA
Load popcorn yield data.
The columns of the 6-by-3 matrix
popcorn contain popcorn yield observations in cups for the brands Gourmet, National, and Generic, respectively.
Perform a one-way ANOVA to test the null hypothesis that the mean yields are the same across the three brands. Use the function
repmat to create a string vector containing factor values for the brand.
factors = [repmat("Gourmet",6,1); repmat("National",6,1); repmat("Generic",6,1)]; aov = anova(factors,popcorn(:),"FactorNames","Brand")
aov = 1-way anova, constrained (Type III) sums of squares. Y ~ 1 + Brand SumOfSquares DF MeanSquares F pValue ____________ __ ___________ ____ __________ Brand 15.75 2 7.875 18.9 7.9603e-05 Error 6.25 15 0.41667 Total 22 17 Properties, Methods
aov is an
anova object that contains the results of the one-way ANOVA.
The small p-value for
Brand indicates that the null hypothesis can be rejected at the 99% confidence level. Enough evidence exists to conclude that at least one brand has a statistically significant difference in mean popcorn yield. You can view this difference by plotting the group means with comparison intervals.
The figure shows the
Gourmet comparison interval in blue and the comparison intervals of
Generic in red. The colors indicate that
Gourmet is statistically different from
Click on the mean of
Generic. The plot now shows the
Generic comparison interval in blue, the
National comparison interval in gray, and the
Gourmet comparison interval in red. The colors indicate that the difference in the mean popcorn yields of
National is not statistically significant.
aov — Analysis of variance results
Analysis of variance results, specified as an
The properties of
aov contain the factors and response data used by
plotComparisons to compute the difference in means.
factors — Factors used to group response data
string vector | cell array of character vectors
Factors used to group the response data, specified as a string vector or cell array of
character vectors. The
plotComparisons function groups the response
data by the combinations of values for the factors in
factors argument must be one or more of the names in
ax — Target axes
Target axes, specified as an
Axes object. If you do not specify the
plotComparisons uses the current axes (
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
the significance level of the confidence intervals to 0.01 and uses an approximation of
Dunnett's critical value to calculate the p-values for the null
hypothesis that group means are not significantly different.
Alpha — Significance level
single | double
Significance level for the comparison intervals, specified as a single or double
between 0 and 1. The confidence level of the comparison intervals is the probability
that the difference between two mean estimates with overlapping intervals is not
statistically significant. The value of
Alpha is given by the
formula . The default value for
Alpha is 0.05.
CriticalValueType — Critical value type
"tukey-kramer" (default) |
Critical value type used by the
plotComparisons function to calculate
p-values, specified as one of the options in the following table.
Each option specifies the statistical test that
plotComparisons uses to
calculate the critical value.
|Honestly Significant Difference test — Same as
|Dunnett's test — Can be used only when |
|Stands for Least Significant Difference and uses the critical value for a plain t-test. This option does not protect against the multiple comparisons problem unless it follows a preliminary overall test such as an F-test.|
Approximate — Indicator to compute Dunnett critical value approximately
Indicator to compute the Dunnett critical value approximately, specified as a numeric
false). You can compute the Dunnett critical value
approximately for speed. The default for
true for an N-way ANOVA with N greater than two, and
false otherwise. This argument is valid only when
ControlGroup — Index of control group factor value
1 (default) | positive integer
Index of the control group factor value for Dunnett's test, specified as a positive
integer. Factor values are indexed by the order in which they appear in
aov.ExpandedFactorNames. This argument is valid only when
 Hochberg, Y., and A. C. Tamhane. Multiple Comparison Procedures. Hoboken, NJ: John Wiley & Sons, 1987.
 Milliken, G. A., and D. E. Johnson. Analysis of Messy Data, Volume I: Designed Experiments. Boca Raton, FL: Chapman & Hall/CRC Press, 1992.
 Searle, S. R., F. M. Speed, and G. A. Milliken. “Population marginal means in the linear model: an alternative to least-squares means.” American Statistician. 1980, pp. 216–221.
Introduced in R2022b