Warning "In log(tmp) : NaNs produced" in MSEM

175 views
Skip to first unread message

Julian Scharbert

unread,
Sep 1, 2022, 5:42:27 AM9/1/22
to lavaan
Hi all,

I have fitted multiple multilevel SEMs with lavaan in multiple datasets, respectively, which all converge without problems and provide reasonable outputs. One model produces a warning message, though, which I do not know how to address. The same model converges in the other datasets and in the same dataset with other predictors, but not in this specific case. I have encountered a comparable warning message in this thread and the author of the post told me that the problem was caused by him using an outdated version of lavaan. I have just installed the newest version of lavaan via 
install.packages("lavaan", repos = "https://www.da.ugent.be/", type = "source")
and the newest r-version, which did not fix the problem, though. 

The model I am trying to fit looks like this:
sem(formula, data=data, cluster="participants")
formula = 
"level:1
l1_outcome~b*l1_predictor
level:2
l1_outcome~c*l2_moderator
l1_predictor~a*l2_moderator
ab:= a*b
total:= ab+c"

The warning message I receive is this (multiple times):
"In log(tmp) : NaNs produced"

I understand that this problem is likely caused by the log() function being applied to a negative value, but I do not understand lavaan well enough to understand why this is the case for the tmp-value. 

Does someone have an idea how to address this problem? The model output looks reasonable to me as well and is comparable to the other predictors / the same predictor with other datasets. So if the warning message can be safely ignored, that would also work for me. 

Thank you in advance! 

Yves Rosseel

unread,
Sep 1, 2022, 6:13:29 AM9/1/22
to lav...@googlegroups.com
Hello Julian,

I would like to investigate this further. Would you be able to email me
your dataset (or a snippet of the datset) and a small R script, so I can
reproduce this?

Please send it to Yves dot Rosseel at UGent dot be

Yves.

On 9/1/22 11:42, 'Julian Scharbert' via lavaan wrote:
> Hi all,
>
> I have fitted multiple multilevel SEMs with lavaan in multiple datasets,
> respectively, which all converge without problems and provide reasonable
> outputs. One model produces a warning message, though, which I do not
> know how to address. The same model converges in the other datasets and
> in the same dataset with other predictors, but not in this specific
> case. I have encountered a comparable warning message in this
> <https://groups.google.com/g/lavaan/c/L0my1YG89K8/m/s6cV7fj4CAAJ>thread
> and the author of the post told me that the problem was caused by him
> using an outdated version of lavaan. I have just installed the newest
> version of lavaan via
> /i//nstall.packages("lavaan", repos = "https://www.da.ugent.be/
> <https://www.da.ugent.be/>", type = "source")/
> //and the newest r-version, which did not fix the problem, though.
>
> The model I am trying to fit looks like this:
> /sem(formula, data=data, cluster="participants")
> /
> /formula = /
> /"level:1/
> /l1_outcome~b*l1_predictor/
> /level:2/
> /l1_outcome~c*l2_moderator/
> /l1_predictor~a*l2_moderator/
> /ab:= a*b/
> /total:= ab+c"/
>
> The warning message I receive is this (multiple times):
> /"In log(tmp) : NaNs produced"/
>
> I understand that this problem is likely caused by the log() function
> being applied to a negative value, but I do not understand lavaan well
> enough to understand why this is the case for the tmp-value.
>
> Does someone have an idea how to address this problem? The model output
> looks reasonable to me as well and is comparable to the other predictors
> / the same predictor with other datasets. So if the warning message can
> be safely ignored, that would also work for me.
>
> Thank you in advance!
>
> --
> 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
> <mailto:lavaan+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/lavaan/9ad9d58a-2561-4294-ae81-220820ca9bebn%40googlegroups.com
> <https://groups.google.com/d/msgid/lavaan/9ad9d58a-2561-4294-ae81-220820ca9bebn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Julian Scharbert

unread,
Sep 1, 2022, 12:38:09 PM9/1/22
to lavaan
Hi all, 

Yves helped me figure out the problem. I had a dev version of lavaan installed (0.6-11.1676). After switching to the current CRAN version (0.6-12), the model did not produce the warning message anymore. Maybe this helps someone with a related problem.

Julian 
Reply all
Reply to author
Forward
0 new messages