Define new variable that is not a combination of others

277 views
Skip to first unread message

Marcus

unread,
May 29, 2018, 6:44:57 PM5/29/18
to lavaan
Dear all,

in Mplus, you often see code like this:

MODEL CONSTRAINT:
    NEW
(rho*.8 beta*0);

Is there a way to define variables in such a way in lavaan, that is, by only providing the starting value of the new variable?

Thanks in advance!

Marcus

Yves Rosseel

unread,
May 31, 2018, 12:23:45 PM5/31/18
to lav...@googlegroups.com
On 05/30/2018 12:44 AM, 'Marcus' via lavaan wrote:
> Dear all,
>
> in Mplus, you often see code like this:
>
> |
> MODEL CONSTRAINT:
>     NEW (rho*.8beta*0);
> |
>
> Is there a way to define variables in such a way in lavaan, that is, by
> only providing the starting value of the new variable?

Do you mean you wish to 'fix' the new variable to a starting value (and
not use it any further?).

You can write this:


HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9

newpar := 4
'

But perhaps you have something else in mind?

Yves.


Marcus

unread,
Jun 15, 2018, 4:47:36 AM6/15/18
to lavaan
Thank you, Yves and sorry for the late response.

Indeed, I need the defined parameter later on and want to use it like this:

MODEL CONSTRAINT:
   
new (rho*.4 beta*0);
 
v_e1
= ((V0) - (V0 * (rho)))/(rho);
v_e2
= ((V0) - (V0 * (rho+   beta)))/(rho+   beta);
v_e3
= ((V0) - (V0 * (rho+ 2*beta)))/(rho+ 2*beta);
v_e4
= ((V0) - (V0 * (rho+ 3*beta)))/(rho+ 3*beta);
v_e5
= ((V0) - (V0 * (rho+ 7*beta)))/(rho+ 7*beta);
v_e6
= ((V0) - (V0 * (rho+11*beta)))/(rho+11*beta);

The V0 parameter is just a label given earlier in the syntax.

Best,

Marcus

Terrence Jorgensen

unread,
Jun 15, 2018, 7:42:42 AM6/15/18
to lavaan
I need the defined parameter later on and want to use it like this:

MODEL CONSTRAINT:
   
new (rho*.4 beta*0);
 
v_e1
= ((V0) - (V0 * (rho)))/(rho);
v_e2
= ((V0) - (V0 * (rho+   beta)))/(rho+   beta);
v_e3
= ((V0) - (V0 * (rho+ 2*beta)))/(rho+ 2*beta);
v_e4
= ((V0) - (V0 * (rho+ 3*beta)))/(rho+ 3*beta);
v_e5
= ((V0) - (V0 * (rho+ 7*beta)))/(rho+ 7*beta);
v_e6
= ((V0) - (V0 * (rho+11*beta)))/(rho+11*beta);

The V0 parameter is just a label given earlier in the syntax. 

Are you trying to implement something like Grimm & Ram (2009)?  http://dx.doi.org/10.1080/10705510903206055

The same trick they mention in Footnote 1 (p. 686) works in lavaan.  You can define a phantom variable as measured by a constant, so it will be automatically unrelated to everything in the model.  If you run example(cfa), you can see this adapted script adds a phantom with zero (co)variance and a fixed mean of 0.4, without changing model fit because it does nothing with that phantom's mean.

HS.model <- ' visual  =~ x1 + x2 + x3

              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9
ph =~ 0
ph ~ 0.4*1
'

fit
<- cfa(HS.model, data=HolzingerSwineford1939)
summary
(fit)

Now, you want to freely estimate rho and beta, which are "free floating" model parameters defined only in the context of other parameters.  So you just need to extend the line that specifies a phantom's mean to both free it, label it, and set the starting value (using the ? operator).

HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 
ph =~ 0
ph ~ NA*1 + label("foo")*1 + .4?1 # free it, label it, start it at .4
'

fit
<- cfa(HS.model, data=HolzingerSwineford1939)
summary
(fit)

And you do that for both rho and beta (i.e., create 2 phantoms, and use their means as placeholders for rho and beta, respectively).  Then you can use those "phantom mean" parameters in your model constraints.  For example, if I want "foo" to be the difference between the second and third loadings of the first 2 factors:

HS.model <- ' visual  =~ x1 + L2*x2 + L3*x3
              textual =~ x4 + L5*x5 + L6*x6

              speed   =~ x7 + x8 + x9
ph =~ 0
ph ~ NA*1 + label("foo")*1 + .2?1
L3 == L2 + foo
L5 == L6 + foo
'

fit
<- cfa(HS.model, data=HolzingerSwineford1939)
summary
(fit)

Of course, if I only include the constraint "L3 == L2 + foo", then the model will be identical to example(cfa).  But your constraints are more complex and serve a different purpose than this illustration.

Good luck,

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


Marcus

unread,
Jun 15, 2018, 8:11:16 AM6/15/18
to lavaan
Hi Terrence,

Are you trying to implement something like Grimm & Ram (2009)?  http://dx.doi.org/10.1080/10705510903206055

Yes, exactly!

Thank you very much for help, great to know how I can make this approach work in lavaan now!

Best,

Marcus


Reply all
Reply to author
Forward
0 new messages