Queries regarding Moderation Analysis in R using Lavaan and semTools

376 views
Skip to first unread message

Harmanjit Singh

unread,
May 12, 2021, 1:10:27 PM5/12/21
to lavaan
Hi,

I used indProd() function to run moderation analysis using R Lavaan and semTools packages.

The analysis ran smoothly. However I came across following issue:
If I use MLM estimator in the sem() function,  for e.g.,
> fit2 <- sem(moderationmodel, estimator="MLM", data = moderationdata,std.lv=TRUE, meanstructure = TRUE) 

Then I get following warning message:
Warning message:
In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
  lavaan WARNING:
    The variance-covariance matrix of the estimated parameters (vcov)
    does not appear to be positive definite! The smallest eigenvalue
    (= -1.999005e-17) is smaller than zero. This may be a symptom that
    the model is not identified

When I inspected this using following:
> lavInspect(fit2, "cov.lv")
I get following output:
                  IV         MOD    DV     IVXMOD
IV             1.000                     
MOD        0.567  1.000              
DV            0.977  0.932  2.183       
IVXMOD -0.521 -0.467 -0.719  1.000

However, if I don't use any estimator (which defauls to ML estimator), then I get no warning message despite the same output of variance-covariance matrix as follows:
> fit2 <- sem(moderationmodel, data = moderationdata,std.lv=TRUE, meanstructure = TRUE)
> lavInspect(fit2, "cov.lv")
                  IV         MOD    DV     IVXMOD
IV             1.000                     
MOD        0.567  1.000              
DV            0.977  0.932  2.183       
IVXMOD -0.521 -0.467 -0.719  1.000

The summary() function runs alike with same results in either case. 
So what does this mean? Since I have used MLM in my CFA and SEM path analysis (due to violation of multivariate normality, I preferred it to default ML estimator, and MLM has given much better model fit results); don't I have to use the same estimator in my moderation analysis? 

Also here are the slope outputs:
$SimpleSlope
      MOD     Slope            SE                   Wald       p
[1,]  -1        0.7653475   0.07849022 9.750865 0.0e+00
[2,]   0        0.5972600   0.07190843 8.305841 0.0e+00
[3,]   1        0.4291725   0.10532919 4.074583 4.6e-05

And attached is the plot (Rplot):

Although I understand from this (and attached plot) that as the moderator increases the impact of IV upon DV decreases, still I would appreciate some source to understand/interpret SimpleSlope outputs shared above in detail. Also, in marketing journals, the moderation analysis is generally represented as showcased in the two attached examples (Moderation examples 1 and 2) herewith. I have used values of moderator as showcased by default in probe2WayMC() function as valProbe(-1,0,1). Does it mean that this is showcasing moderator at means and -1 standard deviation, + 1 standard deviation levels? Or it simply means low, mean, and high moderator levels?

Moderation example 1.jpg
Rplot.jpeg
Moderation example 2.jpg

Terrence Jorgensen

unread,
May 13, 2021, 11:34:13 PM5/13/21
to lavaan
The smallest eigenvalue
    (= -1.999005e-17) is smaller than zero. This may be a symptom that
    the model is not identified

It is a warning that there might be a problem, not an error that there was one.  If your estimates and SEs make sense, then it is probably not an issue.  The smallest eigenvalue is essentially zero, indicating some multicollinearity in the sampling variances of your estimated parameters (not the parameters themselves).

When I inspected this using following:
> lavInspect(fit2, "cov.lv")

That is a function of model parameters, not what the message referred to.

eigen(lavInspect(fit2, "vcov"))
# or merely
eigen(vcov(fit2))

However, if I use ML estimator, then I get no warning message. So what does this mean? 

The linear dependency doesn't exist in the estimated sampling covariances of estimated parameters if you assume normal data; only when using the robust SEs, which are the square-roots of the diagonal of vcov(fit2)

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

Harmanjit Singh

unread,
May 14, 2021, 5:09:48 AM5/14/21
to lav...@googlegroups.com
Thanks Terrence.

This information was helpful.

Kindly comment on the second part of my query, regarding the interpretation of moderation analysis. 

--
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/XbVlvR_iHXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/bdcdfab9-ba71-4c50-b875-007f393f4150n%40googlegroups.com.

Terrence Jorgensen

unread,
May 15, 2021, 12:33:15 AM5/15/21
to lavaan
I have used values of moderator as showcased by default in probe2WayMC() function as valProbe(-1,0,1). Does it mean that this is showcasing moderator at means and -1 standard deviation, + 1 standard deviation levels? 

Not necessarily.  The values in the help-page example were arbitrary, as they probably must be when dealing with latent variables.  But if you want to probe at the mean +/- 1 SD, then you can obtain them from your model output.  lavInspect(fit2, "cov.lv") already showed you that the variances are 1 (so their square-roots are also 1).  You can find the latent-variable means the same way: lavInspect(fit2, "mean.lv")

If those are in fact M=0 and SD=1, then you already have probed the simple slopes at the M +/- 1 SD of the moderator.

Harmanjit Singh

unread,
May 15, 2021, 8:31:06 AM5/15/21
to lav...@googlegroups.com
Thanks Terrence. This indeed is very helpful.
Since, you have pointed towards possibility of multicollinearity in the sampling variances of my estimated parameters, I would deeply appreciate if you can point me towards conducting test for multicollinearity (e.g. VIF) on my dataset. My dataset has multiple IVs, a singleDV and a single moderator (all of them having multiple items each). Couldn't find a way to conduct multicollinearity test in such a scenario. 
Kindly help me with this. 

--
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/XbVlvR_iHXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.

Harmanjit Singh

unread,
Jun 18, 2021, 7:04:54 AM6/18/21
to lavaan
Hi Terrence,

I tried to do multicollinearity test using variation inflation factor (VIF) using 'car' package. Since I am having latent variables in my model, I am unable to figure out how to correctly fit them into lm () function.
I am getting following error:
Error in model.frame.default(formula =  IntermediateVariable ~ IndependentVariableA + IndependentVariableB +   : 
  invalid type (list) for variable ' IntermediateVariable  '
Please help me figure out how to fit it correctly.

The sample code is as follows:

library(car)

IndependentVariableA <- data.frame(Mydata[c("Item1", "Item2" , "Item3" , "Item4")])
IndependentVariableB <- data.frame(Mydata[c("Item5" , "Item6" , "Item7")])
IndependentVariableC <- data.frame(Mydata[c("Item8" , "Item9" , "Item10")])

IntermediateVariable <- data.frame(Mydata[c("Item11" , "Item12" , "Item13" , "Item14")])

DependentVariableA <- data.frame(Mydata[c("Item15" , "Item16")])
DependentVariableB <- data.frame(Mydata[c("Item17" , "Item18", "Item19")])

ModeratingVariable <- data.frame(Mydata[c("Item20" , "Item21" , "Item22" , "Item23")])

# Linear Regression
regressionmodel1 <- lm(IntermediateVariable   ~  IndependentVariableA  +  IndependentVariableB + IndependentVariableC, data = Mydata)
regressionmodel2 <- lm(DependentVariableA   ~  IntermediateVariable   +  IndependentVariableA  +  IndependentVariableB + IndependentVariableC  +  ModeratingVariable, data = Mydata)
regressionmodel3 <- lm( DependentVariableB  ~  IntermediateVariable   +  IndependentVariableA  +  IndependentVariableB + IndependentVariableC  +  ModeratingVariable, data = Mydata)

# VIF 
vif(regressionmodel1)
vif(regressionmodel2)
vif(regressionmodel3)

Harmanjit Singh

unread,
Jun 20, 2021, 11:53:20 PM6/20/21
to lavaan
Gentle reminder.

Terrence Jorgensen

unread,
Jun 21, 2021, 10:53:03 PM6/21/21
to lavaan
Since, you have pointed towards possibility of multicollinearity in the sampling variances of my estimated parameters, I would deeply appreciate if you can point me towards conducting test for multicollinearity (e.g. VIF) on my dataset

No, you are confusing the correlation among variables with the correlation among sample statistics (e.g., in samples with a higher loading for Item2, does Item3's loading also tend to be higher?).  That is not something for which you look at a variance-inflation factor.  You probably don't have to worry about that warning message, unless there is some other evidence that your model is not identified.  It is a warning, not an error.
Reply all
Reply to author
Forward
0 new messages