I am trying to run an R script using lavaan to conduct a Confirmatory Factor Analysis, but this ended up happening.
Error in lav_data_full(data = data, group = group, cluster = cluster, :
lavaan ERROR: unordered factor(s) detected; make them numeric or ordered: T1Bel1 T1Bel2 T1Bel3 T1Bel4 T1Bel5 T1Bel6 T1Bel7 T1Bel8
I tried ordering the values after some googling, but didn't work. The variables McGill, Classmates, and Professors constitute the factors (Likert scale items ranging from 1 to 9, with 9 being the highest and 1 the lowest) as I have coded into the model. Here is my code.
> cfa.t1<-'McGill =~ T1Bel1 + T1Bel2 + T1Bel3 + T1Bel4
+ Classmates =~ T1Bel5 + T1Bel6
+ Professors =~ T1Bel7 + T1Bel8'
> fit.t1 <- cfa(cfa.t1, data=df, meanstructure=TRUE, std.lv=TRUE)
Error in lav_data_full(data = data, group = group, cluster = cluster, :
lavaan ERROR: unordered factor(s) detected; make them numeric or ordered: T1Bel1 T1Bel2 T1Bel3 T1Bel4 T1Bel5 T1Bel6 T1Bel7 T1Bel8
> x<-c(1,2,3,4,5,6,7,8,9)
> value<-factor(x)
> as.ordered(value)
[1] 1 2 3 4 5 6 7 8 9
Levels: 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9
> fit.t1 <- cfa(cfa.t1, data=df, meanstructure=TRUE, std.lv=TRUE)
Error in lav_data_full(data = data, group = group, cluster = cluster, :
lavaan ERROR: unordered factor(s) detected; make them numeric or ordered: T1Bel1 T1Bel2 T1Bel3 T1Bel4 T1Bel5 T1Bel6 T1Bel7 T1Bel8
How do I proceed?