# Design matrix versus contrast matrix [closed]

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?

## closed as off-topic by kjetil b halvorsen, mkt, Michael Chernick, user158565, Peter Flom♦Jul 30 at 10:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mkt, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

• Please give numeric example(s) for all your calculations! Otherwise this is not a statistical but a purely R question and is off-topic then. – ttnphns Jun 20 '14 at 20:06