【问题标题】:Change factor labels in psych::fa or psych::fa.diagram更改 psych::fa 或 psych::fa.diagram 中的因子标签
【发布时间】:2018-05-23 17:59:43
【问题描述】:

我正在使用psych 包进行因子分析。我想在fa() 对象中或使用fa.diagram() 绘图时指定潜在因素的标签。

例如,玩具数据:

require(psych)
n <- 100
choices <- 1:5
df <- data.frame(a=sample(choices, replace=TRUE, size=n), 
                 b=sample(choices, replace=TRUE, size=n), 
                 c=sample(choices, replace=TRUE, size=n), 
                 d=sample(choices, replace=TRUE, size=n))
model <- fa(df, nfactors=2, fm="pa", rotate="promax")

model

Factor Analysis using method =  pa
Call: fa(r = df, nfactors = 2, rotate = "promax", fm = "pa")
Standardized loadings (pattern matrix) based upon correlation matrix
    PA1   PA2   h2   u2 com
a  0.45 -0.49 0.47 0.53 2.0
b  0.22  0.36 0.17 0.83 1.6
c -0.02  0.20 0.04 0.96 1.0
d  0.66  0.07 0.43 0.57 1.0

我想将PA1PA2 更改为FactorAFactorB,方法是更改​​model 对象本身,或者调整fa.diagram() 输出中的标签:

docs for fa.diagram 有一个 labels 参数,但没有示例,而且我到目前为止所做的实验还没有取得成果。非常感谢任何帮助!

【问题讨论】:

    标签: r psych


    【解决方案1】:

    通过str(model),我找到了$loadings 属性,fa.diagram() 使用它来呈现图表。修改 colnames()model$loadings 就可以了。

    colnames(model$loadings) <- c("FactorA", "FactorB")
    fa.diagram(model)
    

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 2023-02-20
      相关资源
      最近更新 更多