Hi All,
I am trying to run a simple SEM with no latent variables. I want to estimate both direct and indirect effects.
1) I'm having trouble getting the model to run in one version of the syntax
2) I'm curious as to how R estimates the indirect effects. Is it based on running separate regression models (which would be based on different theoretical basis than 'true' mediation models)
3) For non-normal data with small sample sizes, I'm not sure which is the best estimator to use (I'll use bootstrapping for the parameter estimates but I'm not sure which "estimator" to include in the model)
Here is my code (the data are attached along with a path model to help clarify what I am looking for. In particular, I have a connection with a double headed arrow that I am not exactly sure how to code for).
data_pa <- read.csv("path_analysis.csv", header = T, sep = ",")
names(data_pa)
M2 <- as.factor(M2) ## M2 is a categorical variable coded as 0 and 1
class(M2)
model <- ' # direct effect
Y ~ a*X + c*M1 + d*M2
# mediator
X ~ b*M1 + e*M2 ## The path between X and M2 would be a double arrow head since X does not really have a direct effect on M2 but there is a link there.
# I'm not exactly sure how to code for the double arrow head in the model.
# indirect effects (b*c) + (d*e)
bc := b*c
de := d*e
# total effect
total := a + c + d + (b*c) + (d*e) ## do I include c and d here in the direct effects too ?
'
fit <- sem(model, ordered ="M2", estimator = "MML", data = data_pa)
fit
summary(fit, rsq = T, standardized = T, fit.measures=TRUE)
I receive this warning message:
** WARNING ** lavaan (0.5-17) model has NOT been fitted
** WARNING ** Estimates below are simply the starting values
If however, I run the model with the following syntax, it works....though, again, I'm not sure that I am including all the interactions that I'm interested in
using this condensed version of the code and I'd like the print out for the direct and indirect effects (which in the tutorials comes with the code above)
(here, I left the data in the spreadsheet as N and Y and re-coded it into 0 and 1 in R...)
data_pa$OWSrecode[data_pa$M2=="N"] <- 0
data_pa$OWSrecode[data_pa$M2=="Y"] <- 1
data_pa$OWSrecode <- as.factor(data_pa$OWSrecode)
model1 <- 'Y ~ X + M1 + OWSrecode
M1 ~ X + OWSrecode
OWSrecode ~ X'
modfit1<- sem(model1, estimator = "WLSMV", data = data_pa, ordered ="OWSrecode")
Many thanks in advance.