1

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?

  • Executing `as.ordered(value)` does NOT change the value of `value`. Needs to be `value <- as.ordered(value)` – IRTFM Jun 24 '21 at 05:40
  • @IRTFM I apologize for the delay in my response, but this did not work. Same error persists, do you have any other suggestions? – Sanheeta Shankar Jun 28 '21 at 14:24
  • It was a guess. If you did it, then executing `class(value)` should now tell you that `value` is ordered. It would not have been prior to my suggestion. However, you should not think that a column inside `df` will in any way affected by that code. So who know what the source of error is? Usually I tell SO newbies that for understanding errors they should include a way to make a data object that can be used for testing code. So in your case that admonition comes a bit late. See [MCVE] – IRTFM Jun 28 '21 at 20:04

0 Answers0