Matrix Algebra and Linear Models

Week 2 - Testing Linear Models

See edX

set.seed(1)
nx <- 5
ny <- 7

Question 2.4.1

You can make a design matrix X for a two group comparison either using model.matrix or simply with:

X = cbind(rep(1,nx + ny),rep(c(0,1),c(nx, ny)))

For a comparison of two groups, where the first group has nx=5 samples, and the second group has ny=7 samples, what is the element in the 1st row and 1st column of X^T X?

(X <- cbind(rep(1, nx+ ny), rep(c(0, 1), c(nx, ny))))
##       [,1] [,2]
##  [1,]    1    0
##  [2,]    1    0
##  [3,]    1    0
##  [4,]    1    0
##  [5,]    1    0
##  [6,]    1    1
##  [7,]    1    1
##  [8,]    1    1
##  [9,]    1    1
## [10,]    1    1
## [11,]    1    1
## [12,]    1    1
crossprod(X)[1,1]
## [1] 12

Question 2.4.2

What are all the other elements of (X^t X)?

crossprod(X)
##      [,1] [,2]
## [1,]   12    7
## [2,]    7    7