R 从psych::fa对象获取标准化加载(“模式矩阵”)

R 从psych::fa对象获取标准化加载(“模式矩阵”),r,psych,factor-analysis,R,Psych,Factor Analysis,函数psych::print.psych()为psych::fa()生成的因子分析对象生成漂亮的输出。我希望获得文本“基于相关矩阵的标准化加载(模式矩阵)”后面的表格,作为数据帧,无需剪切和粘贴 library(psych) my.fa <- fa(Harman74.cor$cov, 4) my.fa #Equivalent to print.psych(my.fa) 我试着检查print.psych(在RStudio中使用View(print.psych))的源代码,但只能找到一个用

函数psych::print.psych()为psych::fa()生成的因子分析对象生成漂亮的输出。我希望获得文本“基于相关矩阵的标准化加载(模式矩阵)”后面的表格,作为数据帧,无需剪切和粘贴

library(psych)
my.fa <- fa(Harman74.cor$cov, 4)
my.fa  #Equivalent to print.psych(my.fa)
我试着检查
print.psych
(在RStudio中使用
View(print.psych)
)的源代码,但只能找到一个用于打印“按组进行因子分析”的标准化加载的部分

my.fa$weights
未标准化,该表缺少h2、u2和com列。如果它们可以标准化,则以下代码可以工作:

library(data.table)
library(psych)
my.fa <- fa(Harman74.cor$cov,4)
my.fa.table <- data.table(dimnames(Harman74.cor$cov)[[1]],
    my.fa$weights, my.fa$communalities, my.fa$uniquenesses, my.fa$complexity)
setnames(my.fa.table, old = c("V1", "V3", "V4", "V5"), 
                      new = c("item", "h2", "u2", "com"))
$weights
替换为
$loadings
将显示以下错误消息:

Error in as.data.frame.default(x, ...) : 
  cannot coerce class ‘"loadings"’ to a data.frame
更新: 添加
[,]
修复了类问题:

library(data.table)
library(psych)
my.fa <- fa(Harman74.cor$cov,4)

my.fa.table <- data.table(dimnames(Harman74.cor$cov)[[1]],
    my.fa$loadings[,], my.fa$communalities, my.fa$uniquenesses, my.fa$complexity)
setnames(my.fa.table, old = c("V1", "V3", "V4", "V5"), 
                      new = c("item", "h2", "u2", "com"))
my.fa.table

我仍然很乐意得到一个更优雅的答案,或者解释为什么这不是内置的。

它不是内置的,因为每个人都想要一些稍微不同的东西。正如您所发现的,您可以通过组合fa中的四个对象来创建一个表:加载、公共性、唯一性和复杂性

   df <- data.frame(unclass(f$loadings), h2=f$communalities, u2= f$uniqueness,com=f$complexity)
 round(df,2)

或者,您可以尝试使用fa2latex,以获得基于LaTex的格式

fa2latex(f)

它产生了一个准APA风格的乳胶表。

它不是内置的,因为每个人都想要一些稍微不同的东西。正如您所发现的,您可以通过组合fa中的四个对象来创建一个表:加载、公共性、唯一性和复杂性

   df <- data.frame(unclass(f$loadings), h2=f$communalities, u2= f$uniqueness,com=f$complexity)
 round(df,2)

或者,您可以尝试使用fa2latex,以获得基于LaTex的格式

fa2latex(f)
它产生了一个准APA风格的乳胶表

  f <- fa(Thurstone,3)
 df <- data.frame(unclass(f$loadings), h2=f$communalities, u2= f$uniqueness,com=f$complexity)
 round(df,2)
                    MR1   MR2   MR3   h2   u2  com
Sentences          0.90 -0.03  0.04 0.82 0.18 1.01
Vocabulary         0.89  0.06 -0.03 0.84 0.16 1.01
Sent.Completion    0.84  0.03  0.00 0.74 0.26 1.00
First.Letters      0.00  0.85  0.00 0.73 0.27 1.00
Four.Letter.Words -0.02  0.75  0.10 0.63 0.37 1.04
Suffixes           0.18  0.63 -0.08 0.50 0.50 1.20
Letter.Series      0.03 -0.01  0.84 0.73 0.27 1.00
Pedigrees          0.38 -0.05  0.46 0.51 0.49 1.96
Letter.Group      -0.06  0.21  0.63 0.52 0.48 1.25
fa2latex(f)