Adding non linear interactions to regressions

431 views
Skip to first unread message

lars.o.m...@gmail.com

unread,
Oct 28, 2013, 9:25:21 AM10/28/13
to lav...@googlegroups.com
Hi
I have until now only used lavaan for modeling linear interactions, but I am interested in how to inplement non linearity into a model. In example my model is :

model <- '
      #Latent variables
 Y1=~ A1 + A2 + A3
 Y2 =~ B1 + B2 +B3
 Y3 =~ C1 + C2 + C3
 Y4 =~ D1 + D2 + D3
 
    #Regressions
Y2 ~ Y1
Y3 ~ Y1
 
Y4 ~ Y2

 '

 fit <- sem(model, data=data, missing="ml", meanstructure=TRUE, fixed.x=FALSE, orthogonal=TRUE, std.lv=FALSE, std.ov=FALSE)
 summary(fit, standardized=TRUE, fit.measures=TRUE)

But I suspect that the link Y4 ~ Y2 is non linear and would like to model that instead, but I can't find the syntax for that. I have tried with Y4 ~ Y2^2, but no luck.

Hope you can help.

Best
Lars O. Mortensen


yrosseel

unread,
Oct 28, 2013, 9:58:13 AM10/28/13
to lav...@googlegroups.com
On 10/28/2013 02:25 PM, lars.o.m...@gmail.com wrote:

> But I suspect that the link Y4 ~ Y2 is non linear and would like to
> model that instead, but I can't find the syntax for that. I have tried
> with Y4 ~ Y2^2, but no luck.

I'm afraid lavaan currently (0.5-14) does not support latent
interactions or quadratic terms for the latent variables...

Yves.

Edward Rigdon

unread,
Oct 28, 2013, 5:04:29 PM10/28/13
to lav...@googlegroups.com
Yves--
     Maybe lavaan lacks special features like the random coefficient method in Mplus, but you can still execute the orthogonalization procedure of Little et al.:
 and replicate Mplus example 5.13.  You create the product indicators and do the orthogonalization (or residualization) outside of lavaan.  I am attaching an edited transcript (pardon my crude R).  This example uses the data from Mplus 5.13.  I am also attaching some slides that give some more detail.
--Ed Rigdon





--
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+unsubscribe@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/groups/opt_out.

interaction lavaan MLR edited.txt
MK 9200 Factor Interactions.pptx

yrosseel

unread,
Oct 29, 2013, 6:07:14 AM10/29/13
to lav...@googlegroups.com
On 10/28/2013 10:04 PM, Edward Rigdon wrote:
> Yves--
> Maybe lavaan lacks special features like the random coefficient
> method in Mplus, but you can still execute the orthogonalization
> procedure of Little et al.:
> http://www.tandfonline.com/doi/abs/10.1207/s15328007sem1304_1#.Um7PPfkqhng
> https://docs.google.com/viewer?url=http%3A%2F%2Frhowell.ba.ttu.edu%2Flittle_bovaird_widaman_2006.pdf
> and replicate Mplus example 5.13.

Yes of course, thanks for reminding me again. It is probably because I
have not implemented the LMS method yet that I keep thinking that users
are asking for this particular missing feature.

In fact, the semTools packages has an 'indProd' function which makes
this a snap to implement.

Yves.

Edward Rigdon

unread,
Oct 29, 2013, 11:12:38 AM10/29/13
to lav...@googlegroups.com
Yves--
Thanks for the tip!  Factor interactions is coming up in my course.
--Ed Rigdon


oolve...@gmail.com

unread,
Oct 30, 2013, 4:50:03 PM10/30/13
to lav...@googlegroups.com

On Tuesday, October 29, 2013 8:12:38 AM UTC-7, Edward Rigdon wrote:
Yves--
Thanks for the tip!  Factor interactions is coming up in my course.
--Ed Rigdon
On Tue, Oct 29, 2013 at 6:07 AM, yrosseel <yros...@gmail.com> wrote:
On 10/28/2013 10:04 PM, Edward Rigdon wrote:
Yves--
      Maybe lavaan lacks special features like the random coefficient
method in Mplus, but you can still execute the orthogonalization
procedure of Little et al.:
http://www.tandfonline.com/doi/abs/10.1207/s15328007sem1304_1#.Um7PPfkqhng
https://docs.google.com/viewer?url=http%3A%2F%2Frhowell.ba.ttu.edu%2Flittle_bovaird_widaman_2006.pdf
  and replicate Mplus example 5.13.

Yes of course, thanks for reminding me again. It is probably because I have not implemented the LMS method yet that I keep thinking that users are asking for this particular missing feature.

In fact, the semTools packages has an 'indProd' function which makes this a snap to implement.

Yves.


--
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 post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/groups/opt_out.

 
 
on a related note... i'm assuming that simulateData( ) does not generate data with a latent interaction? for example, if run the following syntax:
 
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
    
     f1 ~~ 0.3*f2
     f2 ~~ 0.3*f3
     
     #latent regression
     f1~ 0.3*f2+0.3*f3 + f2*f3
         
 '

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


what does it do?
 
i can see it doesn't give me any errors, but the fact that i'm not specifying a regression coefficient for f2*f3 and it's not telling me it's being fixed at 0 makes me suspect f2*f3 is not creating an interaction.
 
if it is not doing it, what is it doing then? is it fixing f3 to the regression coefficient of f2?  

yrosseel

unread,
Nov 2, 2013, 4:03:04 PM11/2/13
to lav...@googlegroups.com
On 10/30/2013 09:50 PM, oolve...@gmail.com wrote:
> on a related note... i'm assuming that simulateData( ) does /not/
> generate data with a latent interaction?

Not by using the 'f2*f3' syntax.

> #latent regression
> f1~ 0.3*f2+0.3*f3 + f2*f3

> what does it do?

It gives the regression coefficient for 'f3' a label, called 'f2'.

Yves.

oolve...@gmail.com

unread,
Nov 4, 2013, 8:25:41 AM11/4/13
to lav...@googlegroups.com
I see. thank you! is there any example on the documentation about how to simulate data in lavaan where a latent interaction (like that f2*f3) is present? if there is not, would you mind sharing one with us, please? it seems like it would be a good thing to have.
 
thank you! 

Terrence Jorgensen

unread,
Nov 5, 2013, 4:08:47 PM11/5/13
to lav...@googlegroups.com


Is there any example on the documentation about how to simulate data in lavaan where a latent interaction (like that f2*f3) is present? if there is not, would you mind sharing one with us, please? it seems like it would be a good thing to have.
 

You could simulate data conforming to the common-factor model "the old-fashioned way," where you generate common and unique factor scores, then combine them using the linear equations that describe your data model.  The steps are essentially:
  1. specify your covariance matrix (and means) among exogenous latent variables
  2. draw a random sample of common factor scores from (1)
  3. specify a regression model for your endogenous latent variables (which can include interactions)
  4. specify a residual covariance matrix for the endogenous latent variables, draw random errors
  5. compute predicted endogenous latent factor scores using (3)
  6. compute latent endogenous factor scores by adding errors from (4) to predicted scores from (5)
  7. specify factor loadings relating the manifest variables to latent factor scores
  8. compute predicted manifest scores using (7)
  9. specify residual covariance matrix for manifest variables, draw errors for each variable
  10. compute manifest variables by adding errors from (9) to predicted scores from (8)
Attached is a script that shows how you would do this for your example.  Since you only had 1 endogenous variable in your example, I skipped the step of specifying the residual covariance matrix of endogenous latent variables, but doing so would entail the same logic described above, and similar to specifying Theta in the attached example.

I've included lots of comments, but let me know if you would like me to clarify anything.

Terry

generateFromDataModel.R
Reply all
Reply to author
Forward
0 new messages