變異數/共變異數計算
在上一個練習中,你已先把 combine 資料前處理成矩陣 A。現在要用 A 來建立此資料集的「變異數-共變異數」矩陣。
本練習屬於課程
R 的資料科學線性代數
練習說明
- 建立矩陣 $\frac{A^TA}{n-1}$,將此矩陣命名為
B。 - 說明
B的[1,1]元素與A第 1 欄的變異數相同。 - 說明
B的[1,2]與[2,1]元素等同於A第 1 欄與第 2 欄之間的共變異數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create matrix B from equation in instructions
B <- ___(A)%*%A/(___(A) - 1)
# Compare 1st element of the 1st column of B to the variance of the first column of A
B[1,1]
____(A[, 1])
# Compare 1st element of 2nd column of B to the 1st element of the 2nd row of B to the covariance between the first two columns of A
B[1, 2]
B[2, 1]
___(A[, 1], A[, 2])