Nov*_*vus 5 r principal pca psych
我的问题是关于心理包中的principal()函数.
set.seed(0)
x <- replicate(8, rnorm(10))
pca.x <- principal(x, nf=4, rotate="varimax")
Run Code Online (Sandbox Code Playgroud)
我知道如果我想查看加载表,我可以使用loading.x <-loadings(pca.x),比我将得到以下结果.
> loading.x
Loadings:
RC1 RC3 RC4 RC2
[1,] -0.892 -0.205 0.123
[2,] 0.154 0.158 0.909
[3,] -0.660 0.255 -0.249 0.392
[4,] -0.352 0.412 0.614 -0.481
[5,] 0.950 -0.208 0.117
[6,] -0.302 0.111 0.860
[7,] 0.852 -0.195 -0.358
[8,] -0.109 0.903 0.265
RC1 RC3 RC4 RC2
SS loadings 2.323 1.934 1.373 1.342
Proportion Var 0.290 0.242 0.172 0.168
Cumulative Var 0.290 0.532 0.704 0.871
Run Code Online (Sandbox Code Playgroud)
我的第一个困惑是装载对象.从技术上讲,它是一个矩阵,但看它的尺寸,它是8*4,这意味着下部不包括在内.
基本上,我想要实现的是单独提取这个部分:
RC1 RC3 RC4 RC2
SS loadings 2.323 1.934 1.373 1.342
Proportion Var 0.290 0.242 0.172 0.168
Cumulative Var 0.290 0.532 0.704 0.871
Run Code Online (Sandbox Code Playgroud)
将它放在data.frame或矩阵中,而不是在控制台中查看它.似乎William Revelle的回答在后期从心理包中的主要功能提取输出作为数据框架.能够单独提取这个下半部分,但print功能仍然给我整个事情.
事实上,我也很好奇开发人员如何构建一个加载对象(我无法通过查看源代码来弄清楚它).此外,我需要的部分我在'pca.x'列表中的其他地方找不到,至少不是格式化的表.我在Mac上使用Rstudio版本0.98.1102,R 3.1.2,以及精神1.5.1.
先感谢您!
小智 7
这部分回答了,但由于这是我的包裹,我会给出一个更完整的答案.
在打印功能中计算PCA或FA因子加载表的汇总表.它被退回(通过打印无形).但是,它可以作为Vaccounted对象使用.
即PCA或FA输出的汇总表
set.seed(0)
x <- replicate(8, rnorm(10))
pca.x <- principal(x, nf=4, rotate="varimax")
p <- print(pca.x)
round(p$Vaccounted,2) #shows the summary of the loadings table
PC1 PC3 PC4 PC2
SS loadings 2.32 1.93 1.37 1.34
Proportion Var 0.29 0.24 0.17 0.17
Cumulative Var 0.29 0.53 0.70 0.87
Proportion Explained 0.33 0.28 0.20 0.19
Cumulative Proportion 0.33 0.61 0.81 1.00
Run Code Online (Sandbox Code Playgroud)
这也适用于fa函数.