Suppose X is the design matrix of my experiment of which I want to model a linear regression model. Such a design matrix can be created by (in this example it is a full factorial design)
library(BHH2) Des2 <- ffDesMatrix(5)
Now, a contrast matrix can be obtained by the following code, corresponding to
( t(X) %*% X)^-1 %*% t(X) (in which
%*% represents matrix multiplication):
solve(t(Des2) %*% Des2) %*% t(Des2)
This results in a matrix giving the Y observations that will be contrasted against each other in order to obtain a parameter estimate (e.g. first row will correspond to beta1).
Now, one can also make a design matrix using the model.matrix function
Des <- as.data.frame(Des2) names(Des) <- c("X1","X2","X3","X4","X5") model.matrix(~X1*X2*X3*X4*X5,data=Des)
This is a model matrix that can be used to estimate all possible interactions between five factorial variables with two levels.
When comparing the columns of the model matrix obtained by the last piece of code with the rows of our contrast matrix, one can note that they are rather similar. The values might be different, but the signs representing the contrasts are identical for a row/column representing the same parameter to be estimated.
My question now refers to these columns and rows: is there any difference to be noted between these two? Or are they identical as in that they both represent contrasts of the Y observations that will be used for estimation of the parameter, and have I thus summed up two equivalent way in obtaining these contrasts?