2017-06-05 40 views
1

我使用PCA从我的数据集here与工具生成的双标图S-加PCA双标图 - 箭长度

运行我的数据的脚本是:

a= princomp(x = ~ ., data = Week.2.Mon.portsweep,scores=T,cor =F) 
a$loadings 
a$scores 
biplot(a,scale=F) 

的双标图结果 here.

用我的知识,我解释双标图如下:

  1. 左&底轴:PC1 & PC2的成绩

  2. 右&顶轴:PC1 & PC2的荷载值

  3. 的观察为黑色,并绘制基于PC的得分

  4. 箭头向量指示哪些变量占PC的大部分。

  5. 箭头名称的位置是基于PC1 PC2 &

  6. 箭头长度的载荷值的组合 - ???

但是,我不知道箭头的长度是基于什么。 我读了一些参考文献,箭头的长度是方差的比例。真的吗?我们如何根据双曲线图来计算它?

你们能帮我吗?谢谢

回答

0

我看着里面的stats:::biplot.princompstats:::biplot.default
箭头的长度计算如下。

(1)指定选项biplot

# Data generating process 
set.seed(12345) 
library(MASS) 
n <- 100 
mu <- c(1,-2,-0.5) 
Sigma <- diag(rep(1,3)) 
X <- mvrnorm(n, mu=mu, Sigma=Sigma) 

pca <- princomp(X, cor=T, scores=T) 
biplot(pca, choices = 1:2, scale = F) 

# Calculates arrow lengths 
lam <- 1 
len <- t(t(pca$loadings[, 1:2]) * lam)*0.8 

# Plot arrows in green and see if overlap the red ones 
mapply(function(x,y) arrows(0, 0, x, y, col = "green", 
      length = .1), x=len[,1], y=len[,2]) 

enter image description here

(2)中指定的biplotscale = 0.5选项。

scale <- 0.5 
biplot(pca, choices = 1:2, scale = scale) 

lam <- (pca$sdev[1:2]*sqrt(pca$n.obs))^scale 
len <- t(t(pca$loadings[, 1:2]) * lam)*0.8 

mapply(function(x,y) arrows(0, 0, x, y, col = "green", length = .1), 
     len[,1], len[,2]) 

enter image description here

+0

嗯,我知道了,谢谢你。 –