[R] How to save the values of the factors of a CFA analysis in my dataset?
Lies Henderickx
lies.henderickx at gmail.com
Fri Mar 16 11:20:16 CET 2018
I performed a CFA using the lavaan package
require('lavaan');
HS.model <- 'external_regulation_soc =~ JOBMOTIVATIE_extsoc1 +
JOBMOTIVATIE_extsoc2 + JOBMOTIVATIE_extsoc3
external_regulation_mat =~ JOBMOTIVATIE_extmat1 +
JOBMOTIVATIE_extmat2 + JOBMOTIVATIE_extmat3
introjected_regulation =~ JOBMOTIVATIE_introj1 +
JOBMOTIVATIE_introj2 + JOBMOTIVATIE_introj3 +
JOBMOTIVATIE_introj4
identified_regulation =~ JOBMOTIVATIE_ident1 +
JOBMOTIVATIE_ident2 + JOBMOTIVATIE_ident3
intrinsic_motivation =~ JOBMOTIVATIE_intrin1 +
JOBMOTIVATIE_intrin2 + JOBMOTIVATIE_intrin3'
fit <- cfa(HS.model, data = dataset, scores="regression")
summary(fit, fit.measures=TRUE, standardized=TRUE)
I managed to get the values for the five factors in a seperate dataset using
data_factor <- predict(fit)
But I need these 5 factors (as columns, as variables), added to my original
dataset. How can I achieve this?
I tried cbind, but got an error:
factorERS <- select(dataset, JOBMOTIVATIE_extsoc1 +
JOBMOTIVATIE_extsoc2 + JOBMOTIVATIE_extsoc3)
data_CFA <- cbind(dataset, fit$scores)
Error in fit$scores : $ operator not defined for this S4 class
Thanks for helping me out!
[[alternative HTML version deleted]]
More information about the R-help
mailing list