Change factor labels in psych::fa or psych::fa.diagram
Asked Answered
S

1

6

I'm using the psych package for factor analysis. I want to specify the labels of the latent factors, either in the fa() object, or when graphing with fa.diagram().

For example, with toy data:

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

I want to change PA1 and PA2 to FactorA and FactorB, either by changing the model object itself, or adjusting the labels in the output of fa.diagram():

fa.diagram

The docs for fa.diagram have a labels argument, but no examples, and the experimentation I've done so far hasn't been fruitful. Any help much appreciated!

Speculum answered 23/5, 2018 at 17:59 Comment(0)
S
7

With str(model) I found the $loadings attribute, which fa.diagram() uses to render the diagram. Modifying colnames() of model$loadings did the trick.

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

fa.diagram

Speculum answered 23/5, 2018 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.