Error message for specify latent variable

223 views
Skip to first unread message

Emy Tìni

unread,
Aug 7, 2024, 6:36:32 AM8/7/24
to lavaan
Hey everyone :) 

I am new on R and more precisely on Lavaan. 
And I met a big issue about the way to enter my latent variable in my model. 
I used each time to function "=~" to specify to R, I am creating my latent variable with indicators. 
Bu each time I tried to realize it, an error message come up explaining my function is non well specify.
I tried to use a hierarchical technique (delete my parameters constraints, even variance and covariance, intercept and so on so see if the issue continue...)

Here is an exemple : 

Model1 <- '
+ #variables latentes
+ ISS =~ ISSA1 + ISSo1 + ISSA2 + ISSC1
+ Sexism =~ SH1 + SH2 + SB1 + SB2 + SB3 + SH3
+
+ #Regression
+ ISS ~ Sexe + Scenario
+ Sexisme ~ ISS + Scenario + Sex'

> fit <- sem(Model1, data = Toutes, estimator = "ML", group = "Sex")

Error: lavaan->ldw_parse_get_modifier():  
   invalid modifier symbol (should be '*' or '?') at line 3, pos 11
+ Sexisme =~ SH1 + SH2 + SB1 + SB2 + SB3 + SH3
                    ^

Maybe someone has already been confronted to this situation ? 

Thank for your answer :) 

Emy

Shu Fai Cheung (張樹輝)

unread,
Aug 7, 2024, 7:11:48 AM8/7/24
to lavaan
Hi,

I believe you need to remove the "+" in each line of the model syntax. I can produce a similar error using the example of cfa() by adding the "+" to each line:

```r
library(lavaan)
#> This is lavaan 0.6-18
#> lavaan is FREE software! Please report any bugs.
HS.model <- '
+ visual  =~ x1 + x2 + x3
+ textual =~ x4 + x5 + x6
+ speed   =~ x7 + x8 + x9
'
fit <- cfa(HS.model, data = HolzingerSwineford1939)
#> Error: lavaan->ldw_parse_get_modifier():  
#>    invalid modifier symbol (should be '*' or '?') at line 2, pos 11
#> + textual =~ x4 + x5 + x6
#>     
```

Removing the "+" removes the error:

```r
HS.model <- '
visual  =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed   =~ x7 + x8 + x9
'
fit <- cfa(HS.model, data = HolzingerSwineford1939)
```

Hope this helps.

-- Shu Fai
Reply all
Reply to author
Forward
0 new messages