R 中的 PCA:如何确定每个变量对 PC 分数的贡献
PCA in R: how to determine contribution of each variable to a PC score
我正在 R 中执行 PCA,如下所示。
# Load data
data(mtcars)
# Run PCA
car.pca <- prcomp(mtcars, scale = TRUE, center = TRUE)
我使用 car.pca$x
获得每辆车的 PC 分数。因此,例如,我知道对于马自达 RX4,PC1 值是 -0.6468627420。我想知道的是,如何计算每个变量对实现此值的贡献?我知道 car.pca$rotation
会给我变量加载。所以,我希望像 mtcars[1,] * car.pca$rotation[, 1]
这样的东西会起作用(即 PC1 的载荷乘以马自达 RX4 的数据),但是,我认为这不能解释数据居中的事实并由 prcomp
函数缩放。在考虑居中和缩放的同时我将如何进行计算?
car.pca$rotation[, 1] * (mtcars[1,] - summary(car.pca)$center) / summary(car.pca)$scale
我正在 R 中执行 PCA,如下所示。
# Load data
data(mtcars)
# Run PCA
car.pca <- prcomp(mtcars, scale = TRUE, center = TRUE)
我使用 car.pca$x
获得每辆车的 PC 分数。因此,例如,我知道对于马自达 RX4,PC1 值是 -0.6468627420。我想知道的是,如何计算每个变量对实现此值的贡献?我知道 car.pca$rotation
会给我变量加载。所以,我希望像 mtcars[1,] * car.pca$rotation[, 1]
这样的东西会起作用(即 PC1 的载荷乘以马自达 RX4 的数据),但是,我认为这不能解释数据居中的事实并由 prcomp
函数缩放。在考虑居中和缩放的同时我将如何进行计算?
car.pca$rotation[, 1] * (mtcars[1,] - summary(car.pca)$center) / summary(car.pca)$scale