I am writing the model syntax for my model to run in lavaan package using R. I have a factor created (which is my independent variable), 4 dependent variables (I will test 4 different models for each separate DV), and I have four moderating variables that I want to include in each model. All variables except the factor are observed variables. I am having difficulty with how to include the moderating variable effects in the syntax. Would it look something like this below? Also, how can I have variables like age and sex as covariates in all models? Thank you for your guidance. Y - DV; F1 - factor; X1 - X4: Moderating variables 1 through 4 Y ~ F1 + F1*X1 + F1*X2 + F1*X3 + F1*X4 |
Y ~ F1 + F1*X1 + F1*X2 + F1*X3 + F1*X4
?formula?lavaanify
F1 + X1 + F1:X1
?indProd
how can I have variables like age and sex as covariates in all models?
Y ~ F1 + X1 + age + sex
First of all, what specifically does the indProd function return as a result? Will it give me the interaction term I am trying to create between the latent factor and each moderator variable?
Y ~ Factor + prodInd1 + prodInd2 + prodInd3 + prodInd4 + Age + Sex
## Latent variable definitionsFactor =~ x1 + x2 + x3 + x4
Interaction =~ prodInd1 + prodInd2 + prodInd3 + prodInd4## residual correlations between items and their product termsx1 ~~ prodInd1x2 ~~ prodInd2x3 ~~ prodInd3x4 ~~ prodInd4## RegressionsY ~ Factor + Interaction + Age + Sex
I then multiplied the output columns (9*var2 * 10*var2 * 11*var2 * 12*var2) and those respective outputs were stored in prodInd1, prodInd2, prodInd3, prodInd4.
- does it make sense to orthogonalize when I have an observed predictor and an observed moderator, and both of them lack normality (as a consequence I assume they are not bivarite normally distributedeither - therefore, I guess from Little 2006 that orthogonalizing works best)?
syntax <- ' y ~ x + z + x:z '- does it make sense to do the same for an observed predictor and a latent moderator with 3 items?
- Oh and by the way @Subam: how did you solve the problem "When I try this, I am receiving an error message which is saying that 'x' must be numeric. I have defined my dataset and am using the name which I assigned it in the 'x' argument position."?
- does it make sense to orthogonalize when I have an observed predictor and an observed moderator, and both of them lack normality (as a consequence I assume they are not bivarite normally distributedeither - therefore, I guess from Little 2006 that orthogonalizing works best)?No, absolutely not. It does nothing but invalidate the interpretations of lower-order effects.
syntax <- ' y ~ x + z + x:z '
But regarding multicollinearity - doesn't it make sense to set the covariance between X and X:M, resp., M and X:M to 0?
N <- 50
set.seed(123)
foo <- data.frame(x = rnorm(N, mean = 3, sd = 1),
m = rnorm(N, mean = 3, sd = 1))
foo$y <- 0 + 6*foo$x + 2*foo$m - 2*foo$x*foo$m + rnorm(N)
## no centering
mod <- lm(y ~ x*m, data = foo)
summary(mod)
## mean-centering
foo$x.mc <- foo$x - mean(foo$x)
foo$m.mc <- foo$m - mean(foo$m)
mod.mc <- lm(y ~ x.mc*m.mc, data = foo)
summary(mod.mc)
## residual-centering
foo$xm <- foo$x*foo$m
mod.xm <- lm(xm ~ x + m, data = foo)
foo$xm.rc <- resid(mod.xm)
mod.rc <- lm(y ~ x + m + xm.rc, data = foo)
summary(mod.rc)
## Notice the un- and mean-centered models make identical predictions.
## Only the x-axis changes.
library(rockchalk)
plotSlopes(mod, plotx = "x", modx = "m")
plotSlopes(mod.mc, plotx = "x.mc", modx = "m.mc")
## main-effects only
mod.main <- lm(y ~ x + m, data = foo)
summary(mod.main)
summary(mod.rc) # smaller SEswant to fit the model with a lavaan-survey-object with cluster-robust standard errors and bootstrapping.
Are you aware of a more elegant way of combining moderation with cluster-adjusted SEs?
I wanted to adjust the SEs to the design using lavaan survey. Unfortunately, my data are also not normally distributed and I have some missings
- bootstrapping to assess the effects of multiple nonnormal mediatiors properly BUT reading this now and having done something else yesterday, I can see that propbably it is not necessary anymore when I use a cluster-robust estimator
MLR needs complete data
But double-mean centering the latent moderators would be necessary, right?
The problem is that I cannot use WLS without getting warnings. I can only fit the model with MLM to a lavaan survey-object of this kind (des2.boot):
Not necessary anymore. lavaan 0.6-2 provides cluster-robust SEs in tandem with FIML for missing (continuous) data.
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
(= -3.451325e-17) is smaller than zero. This may be a symptom that
the model is not identified. Sounds weird but how much do I have to care about this? Is it possible that this is due to unequal cluster sizes? I get the same one when I run a CFA on the included variables only....- bootstrapping to assess the effects of multiple nonnormal mediatiors properly BUT reading this now and having done something else yesterday, I can see that propbably it is not necessary anymore when I use a cluster-robust estimatorIt should not be. The sampling distributions of products of parameters are asymptotically normal, they just require larger N than individual parameters to be "asymptotic". So the delta method is probably sufficient if you have N > 200.
> eigen(inspect(gran1.tot, "cov.lv"))$values
[1] 2.5662824 0.6648205 0.3996176 0.3141911 0.2514984 0.1061096And when I request the eigenvalues, I get the following (which does not look negative at all):> eigen(inspect(gran1.tot, "cov.lv"))$values [1] 2.5662824 0.6648205 0.3996176 0.3141911 0.2514984 0.1061096
eigen(vcov(gran1.tot))Ok now I can see it but what can I do about it? I do not have this problem when I ignore the clusters. So what does that mean (also contentwise)? Are the clusters not meaningful and should be ignored therefore?