J.Sobieszek@elka.pw.edu.pl
2001-Oct-23 08:47 UTC
[R] summary of aov fit on a contrast basis
Hello, In a book (David W. Stockburger, "Multivariate Statistics: Concepts, Models, and Applications", chapter 12 "Contrasts, Special and Otherwise", available online at http://www.psychstat.smsu.edu/multibook) I've found some examples of doing analysis of variance on a contrast basis. I attach my solution (in R, the book uses SPSS) to this problem. Am I computing the same thing, and is there a simpler way of doing that? I would greatly appreciate any comments. Thanks, Jarek -------------- next part -------------- # the data x <- data.frame(G = factor(c(rep(1, 3), rep(2, 3), rep(3, 3), rep(4, 3), rep(5, 3), rep(6, 3))), X = c(1, 2, 3, 5, 6, 7, 9, 10, 11, 1, 2, 3, 1, 2, 3, 1, 2, 3)) # model matrix using contrasts: # c0: 1 1 1 1 1 1 # c1: 2 2 -1 -1 -1 -1 # c2: 0 0 3 -1 -1 -1 # c3: 1 -1 0 0 0 0 # c4: 0 0 0 -2 1 1 # c5: 0 0 0 0 1 -1 CG <- matrix(c(rep(2, 6), rep(-1, 12), rep(0, 6), rep(3, 3), rep(-1, 9), rep(1, 3), rep(-1, 3), rep(0, 21), rep(-2, 3), rep(1, 6), rep(0, 12), rep(1, 3), rep(-1, 3)), ncol = 5, nrow = 18) # fit the aov model (intercept instead of c0, to stop printing of c0's aov) x.aov <- aov(x$X ~ CG[,1] + CG[,2] + CG[,3] + CG[,4] + CG[,5], x = T) # display summary summary(x.aov) # check model matrix x.aov$x
Dear Jarek, There are probably other ways to do this, but one way is to assign the contrasts to the factor; using the data in your data frame x: > attach(x) > > con <- matrix(c(2, 2, -1, -1, -1, -1, + 0, 0, 3, -1, -1, -1, + 1, -1, 0, 0, 0, 0, + 0, 0, 0, -2, 1, 1, + 0, 0, 0, 0, 1, -1), + 6, 5) > > con [,1] [,2] [,3] [,4] [,5] [1,] 2 0 1 0 0 [2,] 2 0 -1 0 0 [3,] -1 3 0 0 0 [4,] -1 -1 0 -2 0 [5,] -1 -1 0 1 1 [6,] -1 -1 0 1 -1 > > contrasts(G) <- con > > summary(lm(X ~ G)) Call: lm(formula = X ~ G) Residuals: Min 1Q Median 3Q Max -1.000e+00 -1.000e+00 -5.551e-17 1.000e+00 1.000e+00 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.000e+00 2.357e-01 16.971 9.40e-10 G1 1.401e-16 1.667e-01 8.41e-16 1.000000 G2 2.000e+00 1.667e-01 12.000 4.84e-08 G3 -2.000e+00 4.082e-01 -4.899 0.000367 G4 2.318e-33 2.357e-01 9.83e-33 1.000000 G5 1.813e-16 4.082e-01 4.44e-16 1.000000 Residual standard error: 1 on 12 degrees of freedom Multiple R-Squared: 0.9333, Adjusted R-squared: 0.9056 F-statistic: 33.6 on 5 and 12 DF, p-value: 1.179e-006 I used lm rather than aov to get the one-df t-tests for each contrast coefficient; these are simply sqrt(F) from your approach. Note that the contrast matrix is given by columns. Is that what you wanted? John At 10:47 AM 10/23/2001 +0200, J.Sobieszek at elka.pw.edu.pl wrote:>Hello, > >In a book (David W. Stockburger, "Multivariate Statistics: Concepts, >Models, and Applications", chapter 12 "Contrasts, Special and >Otherwise", available online at http://www.psychstat.smsu.edu/multibook) >I've found some examples of doing analysis of variance on a contrast >basis. > >I attach my solution (in R, the book uses SPSS) to this problem. > >Am I computing the same thing, and is there a simpler way of doing that? > >I would greatly appreciate any comments. > >Thanks, > >Jarek----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._