[R] Interpretation of high order interaction terms.

RICHARD M. HEIBERGER rmh at temple.edu
Tue Feb 9 22:59:48 CET 2010


## Continuing with the same example, I now show the full set of
contrasts and their
## associated regression coefficients.  Remember that regression coefficients in
## models with factors are meaningful only when the dummy variables
are also displayed.

## construct full set of dummy variables to display all contrasts
sapply(threeway[,2:4], contrasts)  ## default is treatment contrasts
contrasts(threeway$A) <- cbind(Lin=c(-1,0,1), Quad=c(1,-2,1))
contrasts(threeway$B) <- cbind(Lin=c(-1,0,1), Quad=c(1,-2,1))
contrasts(threeway$C) <- cbind(Lin=c(-1,1))
sapply(threeway[,2:4], contrasts)  ## changed to orthogonal
                                   ## integer-valued polynomial contrasts

tw.aov <- aov(Y ~ A * B * C, data=threeway, x=TRUE)
x <- tw.aov$x    ## dummy variables x
t(x)

anova(tw.aov)
beta.hat <- coef(tw.aov)  ## regression coefficients beta.hat

## construct predicted values from beta.hat
y.hat <- x %*% beta.hat
y.hat
fitted(tw.aov)  ## compare to predicted values from fitted function



More information about the R-help mailing list