Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 38.956 13.630 24.625 5.645 Sepal.Width 13.630 16.962 8.121 4.808 Petal.Length 24.625 8.121 27.223 6.272 Petal.Width 5.645 4.808 6.272 6.157 Multivariate Tests: Df test stat approx F num Df den Df Pr(>F) Pillai 1 0.967 1064 4 144<2e-16 Wilks 1 0.033 1064 144<2e-16 Hotelling-Lawley 1 29.552 1064 4 144<2e-16 Roy 1 29.552 1064 4 144<2e-16 linearHypothesis(mod.iris, "Speciesversicolor Speciesvirginica", verbose=TRUE) Hypothesis matrix: (Intercept)Speciesversicolor Speciesversicolor Speciesvirginica 0 1 Speciesvirginica Speciesversicolor Speciesvirginica -1 Right-hand-side matrix: Sepal.Length Sepal.Width Petal.Length Speciesversicolor Speciesvirginica 0 0 0 Petal.Width Speciesversicolor Speciesvirginica 0 Estimated linear function (hypothesis.matrix %*coef rhs): Sepal.Length Sepal.Width Petal.Length Petal.Width -0.652 -0.204 -1.292 -0.700 Sum of squares and products for the hypothesis: Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 10.628 3.325 21.060 11.41 Sepal.Width 3.325 1.040 6.589 3.57 Petal.Length 21.060 6.589 41.732 22.61 Petal.Width 11.410 3.570 22.610 12.25 Sum of squares and products for error: Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 38.956 13.630 24.625 5.645 Sepal.Width 13.630 16.962 8.121 4.808 Petal.Length 24.625 8.121 27.223 6.272 Petal.Width 5.645 4.808 6.272 6.157 Multivariate Tests: 11
Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 38.956 13.630 24.625 5.645 Sepal.Width 13.630 16.962 8.121 4.808 Petal.Length 24.625 8.121 27.223 6.272 Petal.Width 5.645 4.808 6.272 6.157 Multivariate Tests: Df test stat approx F num Df den Df Pr(>F) Pillai 1 0.967 1064 4 144 <2e-16 Wilks 1 0.033 1064 4 144 <2e-16 Hotelling-Lawley 1 29.552 1064 4 144 <2e-16 Roy 1 29.552 1064 4 144 <2e-16 > linearHypothesis(mod.iris, "Speciesversicolor = Speciesvirginica", + verbose=TRUE) Hypothesis matrix: (Intercept) Speciesversicolor Speciesversicolor = Speciesvirginica 0 1 Speciesvirginica Speciesversicolor = Speciesvirginica -1 Right-hand-side matrix: Sepal.Length Sepal.Width Petal.Length Speciesversicolor = Speciesvirginica 0 0 0 Petal.Width Speciesversicolor = Speciesvirginica 0 Estimated linear function (hypothesis.matrix %*% coef - rhs): Sepal.Length Sepal.Width Petal.Length Petal.Width -0.652 -0.204 -1.292 -0.700 Sum of squares and products for the hypothesis: Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 10.628 3.325 21.060 11.41 Sepal.Width 3.325 1.040 6.589 3.57 Petal.Length 21.060 6.589 41.732 22.61 Petal.Width 11.410 3.570 22.610 12.25 Sum of squares and products for error: Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 38.956 13.630 24.625 5.645 Sepal.Width 13.630 16.962 8.121 4.808 Petal.Length 24.625 8.121 27.223 6.272 Petal.Width 5.645 4.808 6.272 6.157 Multivariate Tests: 11
Df test stat approx F num Df den Df Pr(>F) Pillai 1 0.7452 105.3 4 144<2e-16 Wilks 1 0.2548 105.3 4 144<2e-16 Hotelling-Lawley 1 2.9254 105.3 4 144<2e-16 Roy 1 2.9254 105.3 4 144<2e-16 The argument verbose=TRUE to linearHypothesis shows the hypothesis matrix L and right- hand-side matrix C for the linear hypothesis in Equation 4(page 3).In this case,all of the multivariate test statistics are equivalent and therefore translate into identical F-statistics.Both focussed null hypotheses are easily rejected,but the evidence for differences between setosa and the other two iris species is much stronger than for differences between versicolor and virginica. Testing that "0.5*Speciesversicolor +0.5*Speciesvirginica"is 0 tests that the average of the mean vectors for these two species is equal to the mean vector for setosa,because the latter is the baseline ccategory for the Species dummy regressors. An alternative,equivalent,and in a sense more direct approach is to fit the model with custom contrasts for the three species of irises,followed up by a test for each contrast: >C<-matrix(c(1,-0.5,-0.5,0,1,-1),3,2) colnames(C)<-c("setosa vs.versicolor virginica","versicolor virginica") contrasts(iris$Species)<-C contrasts(iris$Species) setosa vs.versicolor virginica versicolor&virginica setosa 1.0 0 versicolor -0.5 1 virginica -0.5 -1 (mod.iris.2 <-update(mod.iris)) Call: 1m(formula cbind(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width) Species,data iris) Coefficients: Sepal.Length Sepal.Width (Intercept) 5.843 3.057 Speciessetosa vs.versicolor virginica -0.837 0.371 Speciesversicolor&virginica -0.326 -0.102 Petal.Length Petal.Width (Intercept) 3.758 1.199 Speciessetosa vs.versicolor virginica -2.296 -0.953 Speciesversicolor&virginica -0.646 -0.350 linearHypothesis(mod.iris.2,c(0,1,0))#setosa vs.versicolor virginica Sum of squares and products for the hypothesis: Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 52.58 -23.28 144.19 59.87 Sepal.Width -23.28 10.30 -63.83 -26.50 12
Df test stat approx F num Df den Df Pr(>F) Pillai 1 0.7452 105.3 4 144 <2e-16 Wilks 1 0.2548 105.3 4 144 <2e-16 Hotelling-Lawley 1 2.9254 105.3 4 144 <2e-16 Roy 1 2.9254 105.3 4 144 <2e-16 The argument verbose=TRUE to linearHypothesis shows the hypothesis matrix L and righthand-side matrix C for the linear hypothesis in Equation 4 (page 3). In this case, all of the multivariate test statistics are equivalent and therefore translate into identical F-statistics. Both focussed null hypotheses are easily rejected, but the evidence for differences between setosa and the other two iris species is much stronger than for differences between versicolor and virginica. Testing that "0.5*Speciesversicolor + 0.5*Speciesvirginica" is 0 tests that the average of the mean vectors for these two species is equal to the mean vector for setosa, because the latter is the baseline ccategory for the Species dummy regressors. An alternative, equivalent, and in a sense more direct approach is to fit the model with custom contrasts for the three species of irises, followed up by a test for each contrast: > C <- matrix(c(1, -0.5, -0.5, 0, 1, -1), 3, 2) > colnames(C) <- c("setosa vs. versicolor & virginica", "versicolor & virginica") > contrasts(iris$Species) <- C > contrasts(iris$Species) setosa vs. versicolor & virginica versicolor & virginica setosa 1.0 0 versicolor -0.5 1 virginica -0.5 -1 > (mod.iris.2 <- update(mod.iris)) Call: lm(formula = cbind(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) ~ Species, data = iris) Coefficients: Sepal.Length Sepal.Width (Intercept) 5.843 3.057 Speciessetosa vs. versicolor & virginica -0.837 0.371 Speciesversicolor & virginica -0.326 -0.102 Petal.Length Petal.Width (Intercept) 3.758 1.199 Speciessetosa vs. versicolor & virginica -2.296 -0.953 Speciesversicolor & virginica -0.646 -0.350 > linearHypothesis(mod.iris.2, c(0, 1, 0)) # setosa vs. versicolor & virginica Sum of squares and products for the hypothesis: Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 52.58 -23.28 144.19 59.87 Sepal.Width -23.28 10.30 -63.83 -26.50 12