问题是关于主成分分析的,部分是手工完成的。
免责声明:我的背景不是数学,而且我是第一次使用 R。
给出了 R^3 中的以下五个数据点。其中 xi1-3 是变量,x1 - x5 是观测值。
| x1 x2 x3 x4 x5
----------------------
xi1 | -2 -2 0 2 2
xi2 | -2 2 0 -2 2
xi3 | -4 0 0 0 4
给出执行主成分分析后的三个主成分向量,如下所示:
Phi1 = (0.41, 0.41, 0.82)T
Phi2 = (-0.71, 0.71, 0.00)T
Phi3 = (0.58, 0.58, -0.58)T
问题如下
1) Calculate the principal component scores zi1, zi2 and zi3 for each of the 5 data points.
2) Calculate the proportion of the variance explained by each principal component.
到目前为止,我已经用以下代码回答了问题 1,其中 Z 代表分数:
A = matrix(
c(-2, -2, 0, 2, 2, -2, 2, 0, -2, 2, -4, 0, 0, 0, 4),
nrow = 3,
ncol = 5,
byrow = TRUE
)
Phi = matrix (
c(0.41, -0.71, 0.58,0.41, 0.71, 0.58, 0.82, 0.00, -0.58),
nrow = 3,
ncol = 3,
byrow = FALSE
)
Z = Phi%*%A
但我不确定如何使用 R 命令重新创建公式,有人可以帮助我吗?
最佳答案
#Here is the numerator:
(Phi%*%A)^2%>%rowSums()
[1] 48.4128 16.1312 0.0000
#Here is the denominator:
sum(A^2)
[1] 64
#So the answer is:
(Phi%*%A)^2%>%rowSums()/sum(A^2)
[1] 0.75645 0.25205 0.00000
我们可以使用prcomp
+summary
进行验证:
summary(prcomp(t(A)))
Importance of components:
PC1 PC2 PC3
Standard deviation 3.464 2.00 0
Proportion of Variance 0.750 0.25 0
Cumulative Proportion 0.750 1.00 1
这大致相同,因为您的 $\Phi$ 四舍五入到小数点后两位。
关于r - R 中的手动主成分分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75139647/