开始使用免费开始使用

方差 / 协方差计算

在上一个练习中,您已将 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])
编辑并运行代码