endogenous moderator in lavaan? I am still learning about SEM, lavaan, and moderated mediation. 
My question is whether a moderator can be an endogenous variable - i.e. whether the variation in the moderator can be modelled as being influenced by the explanatory variables in the model.
For instance, in the following model, "Mod" moderates the indirect effect by the mediator, M1:
require(lavaan)
med_1d.model <- '
M1  ~ a1*X1  + a2*X2  
Y   ~ c1*X1  + c2*X2  + b1*M1 + b2*Mod + b3*M1:Mod
'
fitmedsem_1d <- sem(med_1d.model, dw_1)

Now suppose that we want to account for the variation in "Mod" (which is here a measured variable) by turning it into a (serial) mediator:
med_2d.model <- '
M1  ~ a1*X1  + a2*X2 
Mod ~ a3*X1  + a4*X2 + a5*M1 
Y   ~ c1*X1  + c2*X2 + b1*M1 + b2*Mod + b3*M1:Mod
'
fitmedsem_2d <- sem(med_2d.model, dw_1)

In this case, the fit measures start to bark (when applied to a sample data set not shown here):
fitMeasures(fitmedsem_2d, c("chisq", "df", "pvalue", "cfi", "tli",  "rmsea", "srmr", "AIC", "BIC"))
#chisq       df      pvalue      cfi      tli    rmsea     srmr      aic      bic 
#1101.189    3.000    0.000    0.458   -1.712    0.996    0.191 -665.386 -606.724 

However, if we remove the interaction, the fit measures change quite dramatically, although there is a significant effect for the interaction in the data:
med_3d.model <- '
M1  ~ a1*X1  + a2*X2 
Mod ~ a3*X1  + a4*X2 + a5*M1 
Y   ~ c1*X1  + c2*X2 + b1*M1 + b2*Mod
'
fitmedsem_3d <- sem(med_3d.model, dw_1)

fitMeasures(fitmedsem_3d, c("chisq", "df", "pvalue", "cfi", "tli",  "rmsea", "srmr", "AIC", "BIC"))
#chisq       df   pvalue      cfi      tli    rmsea     srmr      aic      bic 
#0.374    1.000    0.541    1.000    1.008    0.000    0.003 -661.384 -606.633 

As said, the interaction that is removed is significant, and AIC and BIC suggest we should keep the interaction in there. Yet, all the other fit.measures tell us that it should be removed.
Therefore, my question is whether the fit measures (cfi, tli, rmsea, srmr) are indicating a misspecification in the model, when attempting to make the moderator, "Mod", an endogenous variable?
Moreover, I don't understand how removing the interaction can lead to a change in the df from 3 to 1 and a change of chisq of 1101.189 to a chisq of 0.374. Is this a sign that the model has been misspecified? 
 A: In a model with observed variables only, you can count degrees of freedom by counting the excluded paths. Marking the excluded path is important because the chi-square statistic only reacts to excluded or fixed parameter estimates--it is not an F test that assesses the magnitude of included parameter estimates. Generally speaking, chi-square will not give information about whether interaction or quadratic effects should be included / excluded. Keep in mind that adding or removing such effects changes the set of variables in the model, which means that the models are not nested so that chi-square differences are not a sound basis for traditional inference.
In the model corresponding to the med_3d.model syntax, where DF = 1, the one excluded path in this otherwise saturated model is the covariance between X1 and X2. Now, I would have expected lavaan to treat those variables as exogenous and thus to exclude that covariance from its DF calculation, but that is the only source of DF that I can see.
In the model corresponding to the med_2d.model, there are two additional excluded paths, because X1 and X2 have no direct effects on the product term M1*Mod. The syntax says (to me, and more output would clarify) that X1 and X2 have effects on the main variables M1 and Mod, but not on the product.
My suggestion, for clarity, would be to create the interaction term explicitly (M1Mod <- M1 * Mod) and then including that term in your model syntax. You might also use indProd in the semTools package if you want to use, say, double mean centering to ensure that the product is orthogonal to the original variables. Then, in your syntax, you can specify exactly which parameters you want estimated and which will be left fixed at 0.
