Moderation

214 views
Skip to first unread message

Mahima Raina

unread,
Aug 1, 2017, 2:15:30 AM8/1/17
to lavaan
Hi Everyone,

I have a query, would be great if someone can advise me on this. I am trying to run a moderation effect using the code below:

model27<-'PowerT=~DP3+DP4+DP5
ObT=~DOR2+DOR3+DOR5
KnowT=~DK1+DK2+DK3+DK4
DO=~PowerT+ObT+KnowT
DK3~~DK4
BMS=~BMS1+BMS2+BMS3_REV+BMS4+
BMS5_REV+BMS6+BMS7+BMS8
WFC=~WFC1+WFC2+WFC3+WFC4+WFC5
RCW=~RCW1+RCW2+RCW3+RCW4
WFE=~WFE1+WFE2+WFE3
PC=~PC1+PC2+PC3
GRE=~GRE1+GRE2+GRE3+GRE4
WFCust=~WFCust1+WFCust2+WFCust3+WFCust4
IntGRERCW=~GRE*RCW
IntDOPCWFCust=~DO*PC*WFCust
WFC~DO
WFE~DO
WFC~IntGRERCW
WFE~IntGRERCW
WFC~BMS
WFE~BMS
WFC~IntDOPCWFCust
WFE~IntDOPCWFCust'

The output is not generating regressions for the red highlighted part and continues to give output of the previous code. (Interaction of PC*WFCust). Here is the output that was generated :


Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  WFC ~                                                                 
    DO               -0.223    0.258   -0.862    0.389   -0.045   -0.045
  WFE ~                                                                 
    DO                0.290    0.196    1.477    0.140    0.079    0.079
  WFC ~                                                                 
    IntGRERCW         0.056    0.072    0.787    0.431    0.037    0.037
  WFE ~                                                                 
    IntGRERCW         0.632    0.060   10.528    0.000    0.563    0.563
  WFC ~                                                                 
    BMS               0.244    0.082    2.993    0.003    0.121    0.121
  WFE ~                                                                 
    BMS               0.181    0.058    3.098    0.002    0.120    0.120
  WFC ~                                                                 
    IntPCWFCust       0.557    0.045   12.460    0.000    0.616    0.616
  WFE ~                                                                 
    IntPCWFCust      -0.015    0.023   -0.667    0.505   -0.023   -0.023


It also reported an error before it generated output (the code works despite the error).  It is this :

Error in lavaanify(model = FLAT, constraints = constraints, varTable = lavdata@ov,  : 
  lavaan ERROR: wrong number of arguments in modifier (DO,PC) of element IntDOPCWFCust=~WFCust

Can someone help me understand the error and what can be done in this case. Your help is appreciated.

Regards
Mahima

Nikos Korfiatis

unread,
Aug 1, 2017, 8:47:08 AM8/1/17
to lavaan
Lavaan in its current version doesn't have support for latent interaction moderation yet. You need to estimate the interaction manually and specify it as a variable in the model. 

Regards, 

Nikos

Mahima Raina

unread,
Aug 1, 2017, 8:52:04 AM8/1/17
to lav...@googlegroups.com
I did specify this as a variable in the model. IntPCDOWFCust is a new variable that I specify. 

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/Uq-4T4xyvLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

kma...@aol.com

unread,
Aug 2, 2017, 7:04:57 AM8/2/17
to lavaan
Mahima,

Are you sure that you are looking at output generated by the most recent estimation attempt?  When debugging situations like this, I sometimes find it helpful to adopt the following defensive programming idiom.

myModel <- '....'
rm(myFit)
myFit <- lavaan(myModel, ...)
summary(myFit)

That way, you either get output from the most recent estimation attempt or none at all.

Keith
------------------------
Keith A. Markus
John Jay College of Criminal Justice, CUNY
http://jjcweb.jjay.cuny.edu/kmarkus
Frontiers of Test Validity Theory: Measurement, Causation and Meaning.
http://www.routledge.com/books/details/9781841692203/

Mahima Raina

unread,
Aug 2, 2017, 8:48:02 AM8/2/17
to lav...@googlegroups.com
Thank you, Keith. I will try this and let you know. Though, I have been running multiple models with different variables and in the output I can see the changes according to the model defined. I doubt if this is the issue. 


I have tried Z scores and running models with that but no major difference. The problem persists. 

Thanks again,
Regards
Mahima

Alex Schoemann

unread,
Aug 2, 2017, 11:40:55 AM8/2/17
to lavaan
Hi Mahima,

The issue in your code is that you're trying to estimate interactions between latent variables within the syntax. lavaan does not (currently, as far as I know) have this capability (you can estimate interactions for observed predictors, just not latent variables). If you're interested in interactions among latent variables you have two choices the LMS/QML method (implemented in Mplus and the package nlsem) or product indicator approaches (see the indProd function in semTools for details).

Alex


On Wednesday, August 2, 2017 at 8:48:02 AM UTC-4, Mahima Raina wrote:
Thank you, Keith. I will try this and let you know. Though, I have been running multiple models with different variables and in the output I can see the changes according to the model defined. I doubt if this is the issue. 


I have tried Z scores and running models with that but no major difference. The problem persists. 

Thanks again,
Regards
Mahima

On 02-Aug-2017 4:35 PM, "kmarkus via lavaan" <lav...@googlegroups.com> wrote:
Mahima,

Are you sure that you are looking at output generated by the most recent estimation attempt?  When debugging situations like this, I sometimes find it helpful to adopt the following defensive programming idiom.

myModel <- '....'
rm(myFit)
myFit <- lavaan(myModel, ...)
summary(myFit)

That way, you either get output from the most recent estimation attempt or none at all.

Keith
------------------------
Keith A. Markus
John Jay College of Criminal Justice, CUNY
http://jjcweb.jjay.cuny.edu/kmarkus
Frontiers of Test Validity Theory: Measurement, Causation and Meaning.
http://www.routledge.com/books/details/9781841692203/

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/Uq-4T4xyvLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.

Mahima Raina

unread,
Aug 3, 2017, 12:44:51 AM8/3/17
to lav...@googlegroups.com
Hi Alex,

Interesting, I am exploring indProd. However, if you see, two way interactions have worked in the above command (IntPCWFCust_=~PC*WFCust)- is this working fine ?

Thanks ,
Mahima

To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@googlegroups.com.

Alex Schoemann

unread,
Aug 3, 2017, 12:29:49 PM8/3/17
to lavaan
I don't think the two way interactions were working either :(. In lavaan syntax a star, *, cannot be used to specify an interaction between variables. Instead a * is used to create a label for a parameter. So for your two way interactions you were creating a new variable the was equivalent to one of the indicators with a label that was the name of the other indicator. 

For specifying interactions among observed (exogenous) predictors in lavaan you need to use a colon (and also explicitly include lower order terms). 

Mahima Raina

unread,
Aug 3, 2017, 12:31:36 PM8/3/17
to lav...@googlegroups.com
Thanks, Alex. This is really helpful. Appreciate your inputs. 

To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@googlegroups.com.

Mahima Raina

unread,
Aug 23, 2017, 9:01:15 AM8/23/17
to lav...@googlegroups.com
model25<-'PowerT=~DP3+DP4+DP5

ObT=~DOR2+DOR3+DOR5
KnowT=~DK1+DK2+DK3+DK4
DO=~PowerT+ObT+KnowT
DK3~~DK4
BMS=~BMS1+BMS2+BMS3_REV+BMS4+BMS5_REV+BMS6+BMS7+BMS8
WFC=~WFC1+WFC2+WFC3+WFC4+WFC5
RCW=~RCW1+RCW2+RCW3+RCW4
WFE=~WFE1+WFE2+WFE3
WFCust=~WFCust1+WFCust2+WFCust3+WFCust4
WFC~DO
WFE~DO
DO~BMS
BMS~RCW
WFC~RCW
WFC~WFCust
WFE~RCW
WFE~WFCust'

Hi,

I have another question and I am a bit confused. Would appreciate your help. I have to test the above model across two locations (City A and City B). The point is to know if the model shows significant difference in fit across locations. What would be the analyses strategy?
Can I run invariance testing across groups and if Chi square is significant, it claims the models differ significantly?
Is this correct or there is a different way to go about this ?

Thanks in advance,
Mahima

kma...@aol.com

unread,
Aug 24, 2017, 8:27:05 AM8/24/17
to lavaan
Mahima,
Your basic strategy sounds sensible to me.  The usual practice is to fit a sequence of models to better identify the sources of the differences.  Any introduction to measurement invariance will fill in the details for you.

One thing that I notice is that you have 8 latent factors but fewer than 8(8+1)/2 variances and covariances for the latent factors.  Check to make sure that you are not unintentionally constraining some of these to zero.

Also, you have written the model in a way that omits unique variances for the indicators.  So, check your output to confirm that you have used a convenience feature to automatically add these variances.

Mahima Raina

unread,
Aug 24, 2017, 11:18:23 AM8/24/17
to lav...@googlegroups.com
Thank you, sir. I can run invariance tests one by one .
I am not sure if I have completely understood the concerns you have raised above. If your time permits, I can share output with you and we can discuss over email. (could you please let me know where I could email you) ? 

Thanks,
Mahima


kma...@aol.com

unread,
Aug 25, 2017, 9:45:40 AM8/25/17
to lavaan

Mahima,
I went back to look at your code and I think that I partly misunderstood your question (perhaps confusing it with another thread).

If I understand you correctly now, you are not doing measurement invarance but are instead interested in testing the hypothesis that the same mediation model applies in both cities with no differences in parameters across cities.

You still might find it useful to test measurement invarance with a CFA first so that if you find invarance overall you can better determine the source.  Also, invariant regression parameters may not be meaningful without measurement invariance.

You have two options for constraining parameters to equality across your two cities.  You can do this manually by giving the parameter the same name in both cities.

WFE ~ c('a','a')*RCW

However, given that you have a large number of parameters, you may find it helpful to use the group.equal() parameter to impose these constraints on many parameters all at once.  See the Multiple Groups page in the lavaan tutorial for a list of key words and other details.

In your output, check to confirm that you have estimated residual variances for every latent variable (e.g., WFE ~~ WFE) and unique variances for every indicator (e.g., DK3 ~~ DK3).  You appear to be relying on convenience functions to add these to your model.

Mahima Raina

unread,
Aug 25, 2017, 11:07:38 AM8/25/17
to lav...@googlegroups.com
Dear Sir,

Thank you so much. I have run invariance tests until scalar invariance across location, occupation and gender for each latent variable as a first step. 

Yes, you got this absolutely right, I need to see if models differ when parameters are same across groups. So basically I need to constrain regression weights as equal across two groups. 
I will introduce residual and unique variances into the code and post it with output. 

So one unconstrained model vs constrained model and I need to compute difference between the two. I am specifically looking for delta chi sq and delta CFI. What command could we use to generate these deltas ?

Thank you. I really appreciate your help.

Regards,
Mahima



Mahima Raina

unread,
Aug 26, 2017, 3:08:37 AM8/26/17
to lav...@googlegroups.com
Dear Sir,

I have run codes as you suggested. I am attaching a document, would be a great help if you can have a look at the codes and let me know if there are still any issues.

Thanks a lot,

Regards
Mahima
Model Difference.docx

Mahima Raina

unread,
Aug 26, 2017, 3:41:45 AM8/26/17
to lav...@googlegroups.com
Sorry, I made a minor error in interpretation of model difference test:

If the delta chi square is significant it indicates groups differ significantly, and also if delta CFI exceeds the cut off of 0.01, it substantiates the same claim. (I wrote opposite of that for CFI in the document).

Thanks,
Mahima

kma...@aol.com

unread,
Aug 26, 2017, 11:03:59 AM8/26/17
to lavaan
Mahima,
I have not used compareFit() before and would have used the native lavaan function lavTestLRT().  However, I believe that it was an appropriate choice and that you used it correctly.  As long as the only difference between the models involves cross-city equality constraints then the models are nested.  Your interpretation is correct but I would exercise caution with respect to the rule of thumb for delta-CFI.  Keep the basis for that rule of thumb in mind as you interpret the results.  Look at the differences in parameter estimates between the two cities and consider their practical significance.

Mahima Raina

unread,
Aug 27, 2017, 12:09:14 AM8/27/17
to lav...@googlegroups.com
Yes, absolutely, I will.be comparing individual paths across groups but to claim significant differences in model fit I am taking two parameters. I thank you so much for all your help. 

Regards,
Mahima

--

Mahima Raina

unread,
Aug 27, 2017, 12:12:09 AM8/27/17
to lav...@googlegroups.com
Sorry, I forgot to add - I first used lavTestLRT() but it doesnt give delta CFI values so used the other function. 

Mahima Raina

unread,
Oct 15, 2018, 4:17:09 AM10/15/18
to lav...@googlegroups.com
Hi All,

I am conducting a mediation analyses in R for the first time and would appreciate some help in the following code.

DVs : WFC, WFE, FWC, FWE
IV= DO
Mediator : BMS

I am using the following code but I know this has problem in labelling. Since I have four DVs, the labels (representing coefficients a, b, c etc) should vary .. but I dont quite know how to set this code right. Pasting the code here:


modelab<-'PowerT=~DP3+DP4+DP5
ObT=~DOR2+DOR3+DOR5
KnowT=~DK1+DK2+DK3+DK4
DO=~PowerT+ObT+KnowT
DK3~~DK4
BMS=~BMS1+BMS2+BMS4+BMS6+BMS7+BMS8
FWC=~FWC1+FWC2+FWC3+FWC4+FWC5
FC=~FC1+FC2+FC3+FC4
FWE=~FWE1+FWE2+FWE3
WFCust=~WFCust1+WFCust2+WFCust3+WFCust4
WFC=~WFC1+WFC2+WFC4+WFC5
RCW=~RCW1+RCW2+RCW3+RCW4
WFE=~WFE1+WFE2+WFE3
ObT~~0*ObT
DO~~DO
BMS~~BMS
FWC~~FWC
FWE~~FWE
FC~~FC
WFCust~~WFCust
DP3~~DP3
DP4~~DP4
DP5~~DP5
DOR2~~DOR2
DOR3~~DOR3
DOR5~~DOR5
DK1~~DK1
DK2~~DK2
DK3~~DK3
DK4~~DK4
BMS1~~BMS1
BMS2~~BMS2
BMS4~~BMS4
BMS6~~BMS6
BMS7~~BMS7
BMS8~~BMS8
FC1~~FC1
FC2~~FC2
FC3~~FC3
FC4~~FC4
FWC1~~FWC1
FWC2~~FWC2
FWC3~~FWC3
FWC4~~FWC4
FWE1~~FWE1
FWE2~~FWE2
FWE3~~FWE3
WFCust1~~WFCust1
WFCust2~~WFCust2
WFCust3~~WFCust3
WFCust4~~WFCust4
RCW1~~RCW1
RCW2~~RCW2
RCW3~~RCW3
RCW4~~RCW4
WFC1~~WFC1
WFC2~~WFC2
WFC4~~WFC4
WFC5~~WFC5
WFE1~~WFE1
WFE2~~WFE2
WFE3~~WFE3

FWC~WFCust
FWC~FC
BMS~FC
FWE~WFCust
FWE~FC
WFC~RCW
WFE~RCW
BMS~RCW
BMS~a*DO
WFE+WFC+FWC+FWE~b*DO+c*BMS

indirect:=a*b
direct:=c
total:=C*(a*b)'

fit<-sem(modelab,data = ID)
summary(fit,standardized=T,fit.measures=T,rsq=T)

Also, I want bootstrapped results-. The output is coming as follows:

> fit<-sem(modelab,data = ID)
Error in lav_partable_constraints_def(partable, con = LIST, debug = debug) : 
  lavaan ERROR: unknown label(s) in variable definition(s): C
> summary(fit,standardized=T,fit.measures=T,rsq=T)
Error in summary(fit, standardized = T, fit.measures = T, rsq = T) : 
  object 'fit' not found

Thanks for your help in advance. Look forward to yourinput(s).

regards,
Mahima

On Sun, Aug 27, 2017 at 9:42 AM Mahima Raina <mahima...@gmail.com> wrote:
Sorry, I forgot to add - I first used lavTestLRT() but it doesnt give delta CFI values so used the other function. 
On 27-Aug-2017 9:39 AM, "Mahima Raina" <mahima...@gmail.com> wrote:
Yes, absolutely, I will.be comparing individual paths across groups but to claim significant differences in model fit I am taking two parameters. I thank you so much for all your help. 

Regards,
Mahima
On 26-Aug-2017 8:34 PM, "kmarkus via lavaan" <lav...@googlegroups.com> wrote:
Mahima,
I have not used compareFit() before and would have used the native lavaan function lavTestLRT().  However, I believe that it was an appropriate choice and that you used it correctly.  As long as the only difference between the models involves cross-city equality constraints then the models are nested.  Your interpretation is correct but I would exercise caution with respect to the rule of thumb for delta-CFI.  Keep the basis for that rule of thumb in mind as you interpret the results.  Look at the differences in parameter estimates between the two cities and consider their practical significance.

Keith
------------------------
Keith A. Markus
John Jay College of Criminal Justice, CUNY
http://jjcweb.jjay.cuny.edu/kmarkus
Frontiers of Test Validity Theory: Measurement, Causation and Meaning.
http://www.routledge.com/books/details/9781841692203/

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/Uq-4T4xyvLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.

Mahima Raina

unread,
Oct 17, 2018, 3:43:48 AM10/17/18
to lav...@googlegroups.com
An update here:

I have corrected my code (think it is correct) but would help me immensely if someone ca please verify this :

WFC~WFCust

WFE~WFCust

FWE~FC

WFC~RCW

WFE~RCW

BMS~RCW

 

WFC~c1*DO

WFE~c2*DO

FWC~c3*DO

FWE~c4*DO

BMS~a*DO

WFC~b1*BMS

WFE~b2*BMS

FWC~b3*BMS

FWE~b4*BMS

ab1:=a*b1

ab2:=a*b2

ab3:=a*b3

ab4:=a*b4

total1:=c1+(a*b1)

total2:=c2+(a*b2)

total3:=c3+(a*b3)

total4:=c4+(a*b4)'



I have the outputs. However, a strange thing is happening. Earlier, when I wasnt checking for mediation, the paths (DO->BMS, DO-> WFE, DO->FWE were significant. Meaning, direct effects were significant. However, in this output neither direct/nor indirect paths are significant. Can someone please help me understand why this might be happening- is this a wrong code or what does this signify?


Defined Parameters:

                   Estimate  Std.Err  z-value  P(>|z|)

    ab1               0.110    0.134    0.822    0.411

    ab2               0.130    0.115    1.136    0.256

    ab3               0.336    0.233    1.442    0.149

    ab4              -0.036    0.098   -0.368    0.713

    total1            0.340    0.342    0.994    0.320

    total2            0.536    0.428    1.252    0.210

    total3            0.588    0.364    1.615    0.106

    total4            1.430    0.934    1.532    0.126


Really appreciate your help- thanks in advance.


Regards,

Mahima

Terrence Jorgensen

unread,
Oct 18, 2018, 7:37:23 AM10/18/18
to lavaan

WFC~c1*DO

WFE~c2*DO

FWC~c3*DO

FWE~c4*DO

BMS~a*DO

WFC~b1*BMS

WFE~b2*BMS

FWC~b3*BMS

FWE~b4*BMS

ab1:=a*b1

ab2:=a*b2

ab3:=a*b3

ab4:=a*b4

total1:=c1+(a*b1)

total2:=c2+(a*b2)

total3:=c3+(a*b3)

total4:=c4+(a*b4)'


Yes, you have given unique labels to each path, that looks correct.

is this a wrong code or what does this signify?


Hard to guess without seeing parameter estimates from both models.

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

Mahima Raina

unread,
Oct 18, 2018, 10:44:05 AM10/18/18
to lav...@googlegroups.com
Hi Terrance,

Thanks for your email. Here is the complete code that I used:

DVs : WFC, WFE, FWC, FWE
IV= DO
Mediator : BMS


WFC~c1*DO

WFE~c2*DO

FWC~c3*DO

FWE~c4*DO

BMS~a*DO

WFC~b1*BMS

WFE~b2*BMS

FWC~b3*BMS

FWE~b4*BMS

ab1:=a*b1

ab2:=a*b2

ab3:=a*b3

ab4:=a*b4

total1:=c1+(a*b1)

total2:=c2+(a*b2)

total3:=c3+(a*b3)

total4:=c4+(a*b4)'


I was able to find the code for bootstrapping. However, strangely the paths go insignificant (c2,c4,a). Can you help me understand why ?


Thanks again,

Mahima 



--
Reply all
Reply to author
Forward
0 new messages