Practice Worksheet - 2

Question 2

X <- matrix(c(9, 1, 5, 3, 1, 2), nrow=3, ncol=2, byrow=TRUE)

S <- cov(X)
S
     [,1] [,2]
[1,]   16   -2
[2,]   -2    1
# Generalized sample variance
det(S)
[1] 12
# Generalized sample variance of the standardized variables
R <- cor(X)
det(R)
[1] 0.75
# Total sample variance
sum(diag(S))
[1] 17

Question 3

X <- matrix(c(12, 17, 29, 18, 20, 38, 14, 16, 30, 20, 18, 38, 16, 19, 35), nrow=5, ncol=3, byrow=TRUE)

# Sample covariance matrix
S <- cov(X)
S
     [,1] [,2] [,3]
[1,]   10  3.0 13.0
[2,]    3  2.5  5.5
[3,]   13  5.5 18.5
# Generalized sample variance
det(S)
[1] 1.065814e-14
# Verify that the third column of the data matrix is the sum of the first two columns
X[, 3]
[1] 29 38 30 38 35
X[, 1] + X[, 2]
[1] 29 38 30 38 35

Question 4

S <- matrix(c(4, 3, 1, 3, 9, 2, 1, 2, 1), nrow=3, ncol=3, byrow=TRUE)

R <- matrix(c(1, 1/2, 1/2, 1/2, 1, 2/3, 1/2, 2/3, 1), nrow=3, ncol=3, byrow=TRUE)

# Generalized variances
det(S)
[1] 14
det(R)
[1] 0.3888889
# Sample covariance matrix to correlation matrix
cov2cor(S)
     [,1]      [,2]      [,3]
[1,]  1.0 0.5000000 0.5000000
[2,]  0.5 1.0000000 0.6666667
[3,]  0.5 0.6666667 1.0000000

We can observe that R is the corresponding correlation matrix of S.