Example of multigroup dont work anymore...

167 views
Skip to first unread message

johan....@hotmail.com

unread,
Feb 8, 2017, 7:42:12 AM2/8/17
to lavaan
Dear Users,

I'm working on a situation where I want to have partly different models for different groups. I found the following example extremely useful for me, found at: https://groups.google.com/forum/#!topic/lavaan/0eS49Cmgrew

library(lavaan)

HS.model <- '
     group 1:
     visual  =~ x1 + a*x2 + b*x3
     textual =~ x4 + x5 + x6

     group 2:
     visual  =~ x1 + a*x2 + b*x3
     speed   =~ x7 + x8 + x9
'

fit <- cfa(HS.model, data=HolzingerSwineford1939, group="school")

When I found it, it was working fine! Unfortunately, when running the code now I found out that it doesn't work anymore with the following error code:
Error: all(group %in% partable$group) is not TRUE


One solution I tried which didn't work was to specify one model with parameter constraints. But lavaan doesn't allow for speed to be absent from group 1 and textual from group 2. Further, such a solution is much more cumbersome and it is really easy to make mistakes...

Best,
Johan

Yves Rosseel

unread,
Mar 5, 2017, 1:10:10 PM3/5/17
to lav...@googlegroups.com
On 02/08/2017 01:42 PM, johan....@hotmail.com wrote:
> Dear Users,
>
> I'm working on a situation where I want to have partly different models
> for different groups. I found the following example extremely useful for
> me, found at: https://groups.google.com/forum/#!topic/lavaan/0eS49Cmgrew
>
> library(lavaan)
>
> HS.model <- '
> group 1:
> visual =~ x1 + a*x2 + b*x3
> textual =~ x4 + x5 + x6
>
> group 2:
> visual =~ x1 + a*x2 + b*x3
> speed =~ x7 + x8 + x9
> '

This will now work again (0.5-23), IF you change 'group 1:' by 'group:
1'. So first the "group" keyword, then the colon, and then the group
number (or name):

HS.model <- '
group: 1
visual =~ x1 + a*x2 + b*x3
textual =~ x4 + x5 + x6

group: 2
visual =~ x1 + a*x2 + b*x3
speed =~ x7 + x8 + x9
'

fit <- cfa(HS.model, data=HolzingerSwineford1939, group="school")

Yves.

Johan....@hotmail.com

unread,
May 31, 2017, 4:24:41 AM5/31/17
to lavaan
Forgot to thank you! You do great work!
Reply all
Reply to author
Forward
0 new messages