Moderation in lavaan-Pathmodel

236 views
Skip to first unread message

Isa...@hotmail.de

unread,
Apr 26, 2019, 3:54:57 AM4/26/19
to lavaan
Hello,
i have created a path model for checking predictors and moderators in lavaan. Unfortunately R does not show the Fit Statistic (probably because I have too few df). When I covariate variables (e.g. V1~~V2) my df are getting higher and I can see the Fit Statistic . Unfortunately I get the following warning when covariating variablen: 

Warning messages:
1: In lavaan::lavaan(model = med1.txt2, data = Datensatz, estimator = "MLM",  :
  lavaan WARNING: syntax contains parameters involving exogenous covariates; switching to fixed.x = FALSE
2: 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.240869e-17) is smaller than zero. This may be a symptom that
    the model is not identified


Can someone tell me what this means and whether I can still use the model? Unfortunately, I don't know statistics very well and don't know how to deal with the warning. 
And: Sorry for any mistakes, I am not a native speaker. 

Many thanks in advance!

Isa...@hotmail.de

unread,
Apr 26, 2019, 4:02:41 AM4/26/19
to lavaan


Am Freitag, 26. April 2019 09:54:57 UTC+2 schrieb isa...@hotmail.de:
Hello,
i have created a path model for checking predictors and moderators in lavaan. Unfortunately R does not show the Fit Statistic (probably because I have too few df). When I covariate variables (e.g. V1~~V2) my df are getting higher and I can see the Fit Statistic . Unfortunately I get the following warning when covariating variablen: 

When i run my model..

mod1.txt2<-'
SoMePr_z~SK_z
SoMePr_z~Habitus_z
SoMePr_z~Vergnuegen_z
SoMePr_z~IntSN2B
SoMePr_z~IntHN2B
SoMePr_z~IntVN2B
SoMePr_z~IntSNfP
SoMePr_z~IntHNfP
SoMePr_z~IntVNfP
SoMePr_z~IntSDruck
SoMePr_z~IntHDruck
SoMePr_z~IntSFoMO
SoMePr_z~IntHFoMO
SoMePr_z~IntVFoMO
SoMePr_z~Alter_D
SoMePr_z~Social_D
SoMePr_z~N2B_z
SoMePr_z~NfP_z
SoMePr_z~Druck_z
SoMePr_z~FoMO_z
SoMePr_z~Relatedness
N2B_z~~FoMO_z
FoMO_z~~NfP_z
Druck_z~~FoMO_z
N2B_z~~NfP_z
'
med1.fit2<-sem(med1.txt2,estimator = "MLM",data=Datensatz)
summary(med1.fit2,rsquare=T,fit.measures=T)

FIY: SK, Habitus & Vergnuegen are predictors while e.g. IntSN2B is an interaction term to test the moderators.

 .. it get this message:

Terrence Jorgensen

unread,
Apr 26, 2019, 4:08:26 AM4/26/19
to lavaan
R does not show the Fit Statistic (probably because I have too few df)

Are the df zero?  It looks like you are just fitting a multiple regression model (many predictors of one outcome), which has df=0 in covariance-structure analysis.

When I covariate variables (e.g. V1~~V2) my df are getting higher and I can see the Fit Statistic

The first warning tells you why:

switching to fixed.x = FALSE

By default, lavaan sets this TRUE, so any exogenous observed variables are treated as fixed (like in OLS regression) so that no assumptions need to be made about their distribution (i.e., no need for normality of predictors).  Adding the covariance between exogenous predictors indicates they should not be treated as fixed, but should be treated as normally distributed random variables.  This is completely unnecessary, since they are already allowed to covary when treated as fixed (in which case their observed covariance matrix is taken as given, rather than estimated -- hence those parameters do not enter into the DF calculation).

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

Isa...@hotmail.de

unread,
Apr 26, 2019, 4:31:14 AM4/26/19
to lavaan
Are the df zero?  It looks like you are just fitting a multiple regression model (many predictors of one outcome), which has df=0 in covariance-structure analysis.

- If I exclude the covariation of the variables from the model I get 21 df. But the rest of the Fit Statistic like CFI, RMSEA or SRMR won't show. 
- So, if you tell my it looks like i am just fitting a multiple regression model, do you mean this is not a propper path model? Because i did not find any examples for a moderation analysis in a pathmodel so i kind of made this up myself, without knowing if it is right. My advisor told me to create a new variable for the interaction term of the independent variable and the moderator. So i figured my paths must be 1. SoMePr~SK, 2. SoMePr~(SK*Moderator). Thats why i created a lot of interaction variables i just included in the path models. Since i am not doing a mediation analysis i thought the model i created works for my needs. But i am unsure..  Do you have any suggestion how to implement moderators into a path model? I have never done this and cannot find a good example.


By default, lavaan sets this TRUE, so any exogenous observed variables are treated as fixed (like in OLS regression) so that no assumptions need to be made about their distribution (i.e., no need for normality of predictors).  Adding the covariance between exogenous predictors indicates they should not be treated as fixed, but should be treated as normally distributed random variables.  This is completely unnecessary, since they are already allowed to covary when treated as fixed (in which case their observed covariance matrix is taken as given, rather than estimated -- hence those parameters do not enter into the DF calculation).

- Ok, so letting the variables covary is not necessary because lavaan already allows them to covary?

Isa...@hotmail.de

unread,
Apr 26, 2019, 4:48:21 AM4/26/19
to lavaan

Originally i wanted to create my path model like this:

med1.txt4<-'
SoMePr_z~SK_z
SoMePr_z~Habitus_z
SoMePr_z~Vergnuegen_Z
SoMePr_z~SK_z+N2B_z+IntSN2B
SoMePr_z~SK_z+NfP_z+IntSNfP
SoMePr_z~SK_z+Druck_z+IntSDruck
SoMePr_z~SK_z+FoMO_z+IntSFoMO
SoMePr_z~Habitus_z+N2B_z+IntHN2B
SoMePr_z~Habitus_z+NfP_z+IntHNfP
SoMePr_z~Habitus_z+Druck_z+IntHDruck
SoMePr_z~Habitus_z+FoMO_z+IntHFoMO
SoMePr_z~Vergnuegen_z+N2B_z+IntVN2B
SoMePr_z~Vergnuegen_z+NfP_z+IntVNfP
SoMePr_z~Vergnuegen_z+Druckz+IntVDruck
SoMePr_z~Vergnuegen_z+FoMO_z+IntVFoMO
SoMePr_z~Relatedness
'

But i got an ERROR saying: Error in lavParseModelString(model) : 
  lavaan ERROR: duplicate model element in: SoMePr_z~SK_z+NfP_z+IntSNfP 

So this was not possible because some variables are included various times in the model. And R can't handle it somehow..

Terrence Jorgensen

unread,
Apr 27, 2019, 4:43:55 AM4/27/19
to lavaan
Ok, so letting the variables covary is not necessary because lavaan already allows them to covary?

Correct.

  lavaan ERROR: duplicate model element in: SoMePr_z~SK_z+NfP_z+IntSNfP 

So this was not possible because some variables are included various times in the model. And R can't handle it somehow..

All this means is that you can't estimate the same parameter twice.  It looks like you are specifying over a dozen models in one character string.  lavaan does not do stepwise regression.  If you want to fit different models, you have to specify them in different character strings, and fit one model at a time to the data.  

lavaan does covariance-structure analysis, so none of these models will be comparable to each other because they contain different variables.  If you want to compare these models, you need OLS regression (using the lm() function).  Because the only random component in OLS is the outcome('s residuals), you can compare (and test, if nested) models with different predictors.
Reply all
Reply to author
Forward
0 new messages