Load the sample data.
y
is the response vector and g1
, g2
, and g3
are the grouping variables (factors). Each factor has two levels, and every observation in y
is identified by a combination of factor levels. For example, observation y(1)
is associated with level 1 of factor g1
, level 'hi'
of factor g2
, and level 'may'
of factor g3
. Similarly, observation y(6)
is associated with level 2 of factor g1
, level 'hi'
of factor g2
, and level 'june'
of factor g3
.
Test if the response is the same for all factor levels. Also compute the statistics required for multiple comparison tests.
The p-value of 0.2578 indicates that the mean responses for levels 'may'
and 'june'
of factor g3
are not significantly different. The p-value of 0.0347 indicates that the mean responses for levels 1
and 2
of factor g1
are significantly different. Similarly, the p-value of 0.0048 indicates that the mean responses for levels 'hi'
and 'lo'
of factor g2
are significantly different.
Perform multiple comparison tests to find out which groups of the factors g1
and g2
are significantly different.
results = 6×6
1.0000 2.0000 -6.8604 -4.4000 -1.9396 0.0280
1.0000 3.0000 4.4896 6.9500 9.4104 0.0177
1.0000 4.0000 6.1396 8.6000 11.0604 0.0143
2.0000 3.0000 8.8896 11.3500 13.8104 0.0108
2.0000 4.0000 10.5396 13.0000 15.4604 0.0095
3.0000 4.0000 -0.8104 1.6500 4.1104 0.0745
multcompare
compares the combinations of groups (levels) of the two grouping variables, g1
and g2
. In the results
matrix, the number 1 corresponds to the combination of level 1
of g1
and level hi
of g2
, the number 2 corresponds to the combination of level 2
of g1
and level hi
of g2
. Similarly, the number 3 corresponds to the combination of level 1
of g1
and level lo
of g2
, and the number 4 corresponds to the combination of level 2
of g1
and level lo
of g2
. The last column of the matrix contains the p-values.
For example, the first row of the matrix shows that the combination of level 1
of g1
and level hi
of g2
has the same mean response values as the combination of level 2
of g1
and level hi
of g2
. The p-value corresponding to this test is 0.0280, which indicates that the mean responses are significantly different. You can also see this result in the figure. The blue bar shows the comparison interval for the mean response for the combination of level 1
of g1
and level hi
of g2
. The red bars are the comparison intervals for the mean response for other group combinations. None of the red bars overlap with the blue bar, which means the mean response for the combination of level 1
of g1
and level hi
of g2
is significantly different from the mean response for other group combinations.
You can test the other groups by clicking on the corresponding comparison interval for the group. The bar you click on turns to blue. The bars for the groups that are significantly different are red. The bars for the groups that are not significantly different are gray. For example, if you click on the comparison interval for the combination of level 1
of g1
and level lo
of g2
, the comparison interval for the combination of level 2
of g1
and level lo
of g2
overlaps, and is therefore gray. Conversely, the other comparison intervals are red, indicating significant difference.