See edX
Suppose we are analyzing a set of 4 samples. The first two samples are from a treatment group A and the second two samples are from a treatment group B. This design can be represented with a model matrix like so:
X <- matrix(c(1,1,1,1,0,0,1,1), nrow=4)
rownames(X) <- c("a", "a", "b", "b")
X
## [,1] [,2]
## a 1 0
## a 1 0
## b 1 1
## b 1 1
Suppose that the fitted parameters for a linear model give us:
beta <- c(5, 2)
What is the fitted value for the A samples? (The fitted Y values.)
X.a <- X[rownames(X) == "a",]
X.a %*% beta
## [,1]
## a 5
## a 5
What is the fitted value for the B samples? (The fitted Y values.)
X.b <- X[rownames(X) == "b",]
X.b %*% beta
## [,1]
## b 7
## b 7
Suppose now we are comparing two treatments B and C to a control group A, each with two samples. This design can be represented with a model matrix like so:
X <- matrix(c(1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,1,1), nrow=6)
rownames(X) <- c("a","a","b","b","c","c")
Suppose that the fitted values for the linear model are given by:
beta <- c(10,3,-3)
What is the fitted value for the B samples?
X.b = X[rownames(X) == "b",]
X.b %*% beta
## [,1]
## b 13
## b 13
What is the fitted value for the C samples?
X.c = X[rownames(X) == "c",]
X.c %*% beta
## [,1]
## c 7
## c 7