解释 PCA 结果

编程入门 行业动态 更新时间:2024-10-19 10:21:17
本文介绍了解释 PCA 结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在对数据框中的 5 个变量进行主成分分析,以查看可以删除哪些变量.

I am doing a principal component analysis on 5 variables within a dataframe to see which ones I can remove.

df <-data.frame(variableA, variableB, variableC, variableD, variableE) prcomp(scale(df)) summary(prcomp)

给出以下结果

PC1 PC2 PC3 PC4 PC5 Proportion of Variance 0.5127 0.2095 0.1716 0.06696 0.03925

我的问题是,如果我更改数据框中变量的顺序,我会得到相同的结果

My issue is that if I change the order of the variabes in the dataframe, I get the same results

df <-data.frame(variableC, variableF, variableA, variableE, variableB) prcomp(scale(df)) summary(prcomp) PC1 PC2 PC3 PC4 PC5 Proportion of Variance 0.5127 0.2095 0.1716 0.06696 0.03925

我如何知道 5 个变量中的哪个与 PC1 相关,哪个与 PC2 等相关?

How do I know which of the 5 variables is related to PC1, which to PC2 etc?

推荐答案

这里有一种方法来识别解释高达 85% 差异的组件,使用来自 kernlabspam 的数据/代码> 包.

Here is an approach to identify the components explaining up to 85% variance, using the spam data from the kernlab package.

library(kernlab) data(spam) # log transform independent variables, ensuring all values above 0 princomp <- prcomp(log10(spam[,-58]+1)) stats <- summary(princomp) # extract variable importance and list items explaining up to 85% variance importance <- stats$importance[3,] importance[importance <= 0.85]

...和输出:

> importance[importance <= 0.85] PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10 PC11 0.49761 0.58021 0.63101 0.67502 0.70835 0.73188 0.75100 0.76643 0.78044 0.79368 0.80648 PC12 PC13 PC14 0.81886 0.83046 0.84129 >

我们可以得到前 14 个分量的因子分数,如下所示.

We can obtain the factor scores for the first 14 components as follows.

resultNames <- names(importance[importance <= 0.85]) # return factor scores x_result <- as.data.frame(princomp$x[,resultNames]) head(x_result)

...和输出:

> head(x_result) PC1 PC2 PC3 PC4 PC5 PC6 PC7 1 0.7364988 0.19181730 0.041818854 -0.009236399 0.001232911 0.03723833 -0.01144332 2 1.3478167 0.22953561 -0.149444409 0.091569400 -0.148434128 -0.01923707 -0.07119210 3 2.0489632 -0.02668038 0.222492079 -0.107120738 -0.092968198 -0.06400683 -0.07078830 4 0.4912016 0.20921288 -0.002072148 0.015524007 -0.002347262 -0.14519336 -0.09238828 5 0.4911676 0.20916725 -0.002122664 0.015467369 -0.002373622 -0.14517812 -0.09243136 6 -0.2337956 -0.10508875 0.187831101 -0.335491660 0.099445713 0.09516875 0.11234080 PC8 PC9 PC10 PC11 PC12 PC13 PC14 1 -0.08745771 0.079650230 -0.14450436 0.15945517 -0.06490913 -0.042909658 0.05739735 2 0.00233124 -0.091471125 -0.10304536 0.06973190 0.09373344 0.003069536 0.02892939 3 -0.10888375 0.227437609 -0.07419313 0.08217271 -0.12488575 0.150950134 0.05180459 4 -0.15862241 0.003044418 0.01609690 0.01720151 0.02313224 0.142176889 -0.04013102 5 -0.15848785 0.002944493 0.01606874 0.01725410 0.02304496 0.142527110 -0.04007788 6 -0.13790588 0.197294502 0.07851300 -0.08131269 -0.02091459 0.246810914 -0.01869192 >

更多推荐

解释 PCA 结果

本文发布于:2023-10-26 18:46:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531030.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PCA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!