如何计算R中特征向量的百分比方差?

问题描述 投票:0回答:1

我需要计算下面显示的特征向量(特征值)的百分比方差。我还包括了我用来获得目前结果的命令:

colMeans(Chu_data2)

##          V1          V2          V3          V4          V5          V6 
## -0.11900458 -0.21401111 -0.09612128 -0.11873978 -0.00745832 -0.03254005 
##          V7 
## -0.02472377

colMedians(Chu_data2)

## [1] -0.12 -0.18 -0.10 -0.17 -0.10 -0.10 -0.13

colVars(Chu_data2)

## [1] 0.02940187 0.36919574 0.26928803 0.42775589 0.73665904 0.55204203
## [7] 0.59568623

pc = prcomp(Chu_data2)
summary(pc)

## Importance of components:
##                           PC1    PC2     PC3     PC4     PC5     PC6
## Standard deviation     1.5143 0.6333 0.36356 0.24374 0.20140 0.16983
## Proportion of Variance 0.7694 0.1346 0.04435 0.01994 0.01361 0.00968
## Cumulative Proportion  0.7694 0.9040 0.94837 0.96831 0.98192 0.99160
##                           PC7
## Standard deviation     0.1582
## Proportion of Variance 0.0084
## Cumulative Proportion  1.0000

eigenvals <- pc$sdev^2
eigenvals

## [1] 2.29299111 0.40101764 0.13217381 0.05940873 0.04056253 0.02884208
[7] 0.02503294

任何帮助表示赞赏!谢谢。

r variance eigenvector
1个回答
0
投票

特征值(pc$sdev^2 - 正确计算 - 见?prcomp)相当于排序的每个轴的方差。您可以通过不同方式计算它们:

正如@Onyamby建议的那样,您可以计算您的特征值比例:

## Example data
example <- prcomp(USArrests, scale = TRUE)
## Eigen values
eigenvals <- example$sdev^2
## Proportional eigen values
eigenvals/sum(eigenvals)
#[1] 0.62006039 0.24744129 0.08914080 0.04335752

或者更简单地说,这只是每轴方差的比例:

## Summarizing the ordination
summary(example)
#Importance of components:
#                          PC1    PC2     PC3     PC4
#Standard deviation     1.5749 0.9949 0.59713 0.41645
#Proportion of Variance 0.6201 0.2474 0.08914 0.04336
#Cumulative Proportion  0.6201 0.8675 0.95664 1.00000

## The variation per ordination axis
summary(example)$importance[2,]
#    PC1     PC2     PC3     PC4 
#0.62006 0.24744 0.08914 0.04336 

或者,或者:

## Variance per axis
var_axis <- apply(example$x, 2, var)

## Proportional variance
var_axis/sum(var_axis)
#       PC1        PC2        PC3        PC4 
#0.62006039 0.24744129 0.08914080 0.04335752 
© www.soinside.com 2019 - 2024. All rights reserved.