Error in Analysis of indirect and total effects (Error in parse(file = "", text = BODY.txt) : <text>:62:1: unexpected 'in')

49 views
Skip to first unread message

Anvar Sanaei

unread,
Jan 18, 2020, 11:13:45 PM1/18/20
to lavaan
Dear all,

I do appreciate if someone might be able to help me for fixing the following error. I have a very complex SEM, but when I want to calculate indirect and total effects I see this error (no error when I run just direct effect and high model fit statistics). my model consist of 23 direct effects, 43 indirect paths and also 21 total effects. I also run exactly the inverse of this model, but there is no error for the inverse model. 
Error in parse(file = "", text = BODY.txt) : <text>:62:1: unexpected 'in'
61: cj <- c*j
62: in
    ^
Thanks in advance.
Best Regards,
Anvar,

Terrence Jorgensen

unread,
Jan 20, 2020, 10:46:56 AM1/20/20
to lavaan
I also run exactly the inverse of this model

What does that mean?  Are the causal effects in the opposite direction?
 
It is impossible to know what might lead to your error without seeing an R script that produces the error.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Anvar Sanaei

unread,
Jan 21, 2020, 8:47:05 PM1/21/20
to lav...@googlegroups.com
Dear Terrence,
Thanks for your reply. yes, exactly, I want to test the bottom-up and also the top-down effects, so I have also the same model but with the opposite direction. 
attached are my R codes. please see.
Thanks once again.
Best Regards,
Anvar,

--
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/ceef1c8c-db5f-4b74-8536-a1eb27a91ae2%40googlegroups.com.
R codes.txt

Terrence Jorgensen

unread,
Jan 22, 2020, 4:41:31 AM1/22/20
to lavaan
attached are my R codes

I can't run them without data, but lavaanify() parses both model1 and modela1 without an error.  When in the script does the error happen? 

Anvar Sanaei

unread,
Jan 22, 2020, 6:37:18 AM1/22/20
to lav...@googlegroups.com
Dear Terrence,
Thanks again. I attached my data and also R codes here. here I got the error after running indirect and total effects codes. here: 
fita1 <- sem(modela1, data = Data)
Thanks.
Best Regards,
Anvar,

--
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.
R codes.txt
Data.csv

Terrence Jorgensen

unread,
Jan 22, 2020, 3:33:39 PM1/22/20
to lavaan
OK, this was a funny one.  One of your indirect effects was called "in" (product of paths i and n).  "in" is a reserved word in R:

?reserved

It is used to define the vector over which to loop (e.g., for (i in 1:3) {...}).  Any syntax will fail if you try to name something "in", but the error is much more informative if that thing is a variable instead of a parameter:

Data$in <- Data$HSR
model1
<- ' in ~ CWP '
fit1
<- sem(model1,data=Data, fixed.x=FALSE)
model1
<- ' HSR ~ in*CWP '
fit1
<- sem(model1,data=Data, fixed.x=FALSE)


Error in lavParseModelString(model) :
  lavaan ERROR
: left hand side (lhs) of this formula:
   
in ~ CWP
    contains either a reserved word
(in R) or an illegal character: in
    see
?reserved for a list of reserved words in R
    please
use a variable name that is not a reserved word in R
   
and use only characters, digits, or the dot symbol.

I reported it on GitHub, so hopefully the next version of lavaan will print a more informative error message like the one above.

Anvar Sanaei

unread,
Jan 23, 2020, 12:33:14 AM1/23/20
to lav...@googlegroups.com
Dear Terrence,
thanks for your effort. it is strange, why not such error for the inverse model? do I have to wait for the respond from GitHub? do you think this error will be fix soon? because I'm doing this research now.
Thanks!
Best Regards,
Anvar,
A


--
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.

Terrence Jorgensen

unread,
Jan 25, 2020, 3:23:59 AM1/25/20
to lavaan
why not such error for the inverse model?

I don't know, you didn't provide that syntax.  But if there is no error, I can only guess you are not defining a parameter called "in".

 
do I have to wait for the respond from GitHub? 

No, as I said, you just can't name the parameter "in".  You can capitalize to call it "IN", which will avoid the error.

Anvar Sanaei

unread,
Jan 25, 2020, 10:01:50 PM1/25/20
to lav...@googlegroups.com
Dear Terrence,
sorry, I did not understand your mean about using "IN" instead "in" in R codes as I'm not specialist in this area, I'm just a user. 
as I said you before, for the direct effects analysis I did not get the error, just for indirect effects I had.
how can I fix this error for indirect effects?
Thanks once again.
Best regards,
Anvar,

--
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.

Terrence Jorgensen

unread,
Jan 28, 2020, 4:02:04 AM1/28/20
to lavaan
as I said you before, for the direct effects analysis I did not get the error, just for indirect effects I had.

I thought you said "reversing" the effects did not lead to an error.  Indeed, you did not label any direct effects "in", so there would be no error if the word "in" was not in your lavaan syntax.


how can I fix this error for indirect effects?

By doing what I said before:  You just can't name the parameter "in".  You can capitalize to instead call that indirect effect "IN", which will avoid the error.
Reply all
Reply to author
Forward
0 new messages