When using predict
for a fitted model in package lavaan
, we can obtain the factor scores (fscores). However, by default these fscores are all made to have a mean of 0
(i.e., centered).
However, I want to compare fscores from two factors to see their difference. How can I compare the fscores of lavaan package?
Here is reproducible data and R code:
set.seed(0)
D <- mapply(sample, 6, rep(18, 6), T) # DATA
colnames(D) <- paste0("v", 1:6)
library(lavaan) # MODEL
m1 <- " f1 = ~v1+v2+v3
f2 = ~v4+v5+v6 "
fit1 <- cfa(m1, data = D) # RUN lavaan
fscore <- data.frame(predict(fit1)) # Get fscores
round(c(f1.mean = mean(fscore$f1), f1.sd = sd(fscore$f1), f2.mean = mean(fscore$f2), f2.sd = sd(fscore$f2)), 3)
#> f1.mean f1.sd f2.mean f2.sd ## Notice both f1 and f2 have a mean of ZERO.
0.000 0.511 0.000 2.141 # How to compare f1 with f2