gpt4 book ai didi

r - psych:主要 - 加载组件

转载 作者:行者123 更新时间:2023-12-04 18:05:46 24 4
gpt4 key购买 nike

我的问题与 psych 包中的 principal() 函数有关。

set.seed(0)
x <- replicate(8, rnorm(10))
pca.x <- principal(x, nf=4, rotate="varimax")

我知道如果我想查看loadings表,我可以使用 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

我的第一个困惑是 loadings 对象。从技术上讲,它是一个矩阵,但是看它的维度,它是 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

要么将它放在 data.frame 或矩阵中,而不是在控制台中查看它。似乎 William Revelle 在帖子中的回答 Extracting output from principal function in psych package as a data frame .能够单独提取这个下部,但 print功能仍然给了我整个事情。

其实我也很好奇开发者是怎么构造一个加载对象的(看源码看不懂)。另外,我需要的部分在“pca.x”列表的其他地方找不到,至少不是格式化的表格。
我在 Mac 上使用 Rstudio 版本 0.98.1102、R 3.1.2 和 psych 1.5.1。

先感谢您!

最佳答案

这是部分回答,但由于它是我的包裹,我将给出更完整的答案。

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

这也适用于 fa 函数。

关于r - psych:主要 - 加载组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28635510/

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