Error in out$XX3.null : $ operator is invalid for atomic vectors

80 views
Skip to first unread message

Mafalda Campos

unread,
Sep 12, 2023, 11:26:15 AM9/12/23
to lavaan
Hey everyone,

I'm trying to conduct a simple second-order CFA. First-order unidimensional version works fine (bad fit, but syntax runs smoothly). However, by trying to do a two-factor second-order solution, I get the error Error in out$XX3.null : $ operator is invalid for atomic vectors in the line of code  summary (early_ltask1_v2_fit,fit.measures=T,standardized=T).


Here's the syntax:
early_ltask1_v2 <- 'factor1 =~elt1 + elt2 + elt3 + elt4
factor2 =~ elt5 + elt6
mainfactor =~ factor1 + factor2'
early_ltask1_v2_fit <- sem(early_ltask1_v2, data=dataset, ordered=T, estimator= "WLSMV")
summary (early_ltask1_v2_fit,fit.measures=T,standardized=T)
modindices(early_lact1_v2_fit,standardized = T)
compRelSEM (early_ltask1_v2_fit, ord.scale=T)
reliability (early_ltask1_v2_fit)

Any idea how to fix this?

Victor Avasi

unread,
Sep 12, 2023, 11:57:27 AM9/12/23
to lav...@googlegroups.com
Mafalda,
Redefine your dataset as a data frame and rerun the code. It seems that dataset is defined as an atomic vector in the opening code that you didn't share.

Note that line 8 may throw an error as well since as far as I can tell, an argument early_lact1_v2_fit calls an undefined function.

Regards,

Victor

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/a3bf069c-ff1a-402d-a984-de3b3c97a666n%40googlegroups.com.

Mafalda Campos

unread,
Sep 12, 2023, 12:22:38 PM9/12/23
to lavaan
Hey Victor,
Thank you for taking the time to help me!

Unfortunately, the data was imported as a data frame so that should not be the issue. I am guessing maybe it has something to do with the syntax for the model? The thing is that everything works until I either include a second-order factor or a method factor, for instance. That's when I get the error...

Best,
Mafalda.

Jeremy Miles

unread,
Sep 13, 2023, 8:03:12 PM9/13/23
to lav...@googlegroups.com
I'm not sure about this error, but I don't think your model is identified.  

You have two first order factors, which have a covariance. 

If you replace 

mainfactor =~ factor1 + factor2

With

factor1 ~~ factor2

This model is equivalent to the model you want. 

Your second order factor is trying to estimate two things (mainfactor's variance, and the loading of factor2) but it's only got one piece of information to do that with - and you can't estimate two things using one thing.

You can fix both loading to one. 

mainfactor =~ 1 * factor1 + 1 * factor2

And then the variance of mainfactor will be equal (I think) to the covariance of factor1 and factor2 in the model I specified.

Hope that helps,

Jeremy





--

Shu Fai Cheung (張樹輝)

unread,
Sep 13, 2023, 8:06:24 PM9/13/23
to lavaan
I am not 100% certain but it may be a bug, or an error that is not detected.

In the source, if the computation of `out` (when computing CFI) leads to an error, `out` is supposed to be a try-error (due to the method, not a bug per se) that can be detected, and then you will not see the affected fit measures, without any error message.

However, in your case, it seems that somehow something's wrong in computing `out` but did not result in an error, resulting in the error message you received.

You can check whether it is due to fit measures by removing `fit.measures=T` when calling summary():

summary (early_ltask1_v2_fit,standardized=T)

If the error is due to fit measures computation, this should not result in an error (unless there are other issues).

You can also run this:

fitMeasures(early_ltask1_v2_fit, "cfi", output = "text")

This asks for *only* the CFI. My guess is, this will result in the same error message you received.

You may consider creating an issue at GitHub:


Hope this helps.

-- Shu Fai

Shu Fai Cheung (張樹輝)

unread,
Sep 13, 2023, 8:11:40 PM9/13/23
to lavaan
Oh .... I missed the post by Jeremy. That problem is more important, whether summary() results in an error or not. Sorry.

-- Shu Fai

P.S.: it may still be good to detect that error in computing CFI, if my guess is right, given that try() is already used and the error indicates that there may be error conditions it fails to detect.

Mafalda Campos

unread,
Sep 16, 2023, 8:13:51 AM9/16/23
to lavaan
Dear Jeremy,
Thank you! Your explanation was quite helpful and I was able to advance with my analysis.
Much appreciated!
Best,
M.

Mafalda Campos

unread,
Sep 16, 2023, 8:15:07 AM9/16/23
to lavaan
Shu,
Thank you for your help and time trying to give me a hand on this! It was in fact related to what Jeremy had mentioned.
Best,
M. 

Reply all
Reply to author
Forward
0 new messages