order of syntax makes error appear/disappear?

502 views
Skip to first unread message

oolve...@gmail.com

unread,
Dec 13, 2013, 6:32:38 AM12/13/13
to lav...@googlegroups.com
hello again. a few days ago both Ed and Yves helped me understand some of the issues related with specifying both latent regressions AND covariances between latent variables. when i kept on tinkering with that sytnax, however, i'm finding that (what i think) is the same syntax makes the error appear/disappear. all i'm changing is the order in which one variable appears.
 
my example. if i do this:
 
three.factor <-
    
    '#model
    
     f1=~ 0.7*y1 + 0.7*y2 + 0.7*y3
     f2=~ 0.7*y4 + 0.7*y5 + 0.7*y6
     f3=~ 0.7*y7 + 0.7*y8 + 0.7*y9 
    
     #variances
    
     f1~~1*f1
     f2~~1*f2
     f3~~1*f3
     
     #covariances
          
      f2 ~~ 0.5*f3
      f1 ~~ 0.5*f2
      f3 ~~ 0.5*f1
     
     #latent regression
    
      f1~ 0.3*f3
         
 '
datum <- simulateData(three.factor, sample.nobs=1000)

 

lavaan gives me the error we discussed before, where i'm trying to specify both a regression dependency and a dependency betwen the residuals of f1 and the variance of f3.
 
Error in lavParseModelString(model.syntax = model, warn = warn, debug = FALSE) :
  lavaan ERROR: duplicate model element in: f1~0.3*f3

 

BUT if i change the order of f3 ~~ 0.5*f1 TO f1 ~~ 0.5*f3 i get NO ERROR
 
three.factor <-

'#model

f1=~ 0.7*y1 + 0.7*y2 + 0.7*y3
f2=~ 0.7*y4 + 0.7*y5 + 0.7*y6
f3=~ 0.7*y7 + 0.7*y8 + 0.7*y9

#variances

f1~~1*f1
f2~~1*f2
f3~~1*f3

#covariances

f2 ~~ 0.5*f3
f1 ~~ 0.5*f2
f1 ~~ 0.5*f3 #<----- THE CHANGE HAPPENED HERE
     
     #latent regression

f1~ 0.3*f3

'
datum <- simulateData(three.factor, sample.nobs=1000)

the same thing happens if instead of simulateData() i use the sem() function

three.factor1 <-
     '#model
    
     f1=~ NA*y1 + y2 + y3
     f2=~ NA*y4 + y5 + y6
     f3=~ NA*y7 + y8 + y9 

 

    
     #variances
    
     f1~~1*f1
     f2~~1*f2
     f3~~1*f3
     
     #covariances     

     f2 ~~ f3
     f1 ~~ f3
    
     #latent regressions
      f1~f3

 '
summary(sem(three.factor1, datum), rsquare=TRUE, standardized=TRUE)

 

as you can see, i'm including both f1 ~ f3 and f1 ~~~f3 and no error gets reported. i obtain parameter estimates, the model converges, everything works perfectly.
 
what is the difference then between telling lavaan f1 ~~ f3 and f3 ~~ f1? i thought they both meant the same!
 

 
 
 
 

yrosseel

unread,
Dec 14, 2013, 4:10:41 AM12/14/13
to lav...@googlegroups.com
On 12/13/2013 12:32 PM, oolve...@gmail.com wrote:
> hello again. a few days ago both Ed and Yves helped me understand some
> of the issues related with specifying both latent regressions AND
> covariances between latent variables. when i kept on tinkering with that
> sytnax, however, i'm finding that (what i think) is the same syntax
> makes the error appear/disappear. all i'm changing is the order in which
> one variable appears.

True. You have found a weakness in the syntax parser of (<=) 0.5-14.
But, this has been addressed in the current version 0.5-15. Please
update, but keep experimenting! And let us know if you find any other
syntax based issues. We need this to be perfect.

Yves.

oolve...@gmail.com

unread,
Dec 14, 2013, 5:06:25 AM12/14/13
to lav...@googlegroups.com
thank you, yves! i'll update right away and will keep on looking at this in detail.
 
i'm such a lavaan enthusiast i really want it to be perfect too!
Reply all
Reply to author
Forward
0 new messages