gpt4 book ai didi

r - R : how to determine contribution of each variable to a PC score 中的主成分分析

转载 作者:行者123 更新时间:2023-12-02 01:13:30 27 4
gpt4 key购买 nike

我正在 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 - R : how to determine contribution of each variable to a PC score 中的主成分分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43811572/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com