1. Simplest mediation with all continuousvariablez It works
#Generated data (I use the example from Grace 2006, p. 46, Fig. 3.5)
N <- 10000
x <- rnorm(N)
y1 <- 0.55*x + rnorm(N)
y2 <- 0.24*x + 0.47*y1 + rnorm(N)
LinearMedData <- data.frame(x, y1,y2)
write.xlsx(LinearMedData, "C:/Users/gaiarrido/Desktop/LinearMedData.xlsx") # write sheet
#Data analysis
LinearMedMod <- 'y1~a*x
y2~b*x+ c*y1
'
fitLinearMedMod <- sem(LinearMedMod, data = LinearMedData)
summary(fitLinearMedMod)
Regressions:
Estimate Std.Err z-value P(>|z|)
y1 ~
x (a) 0.548 0.010 55.612 0.000
y2 ~
x (b) 0.244 0.011 21.539 0.000
y1 (c) 0.456 0.010 45.379 0.000
Variances: Estimate Std.Err z-value P(>|z|)
.y1 0.981 0.014 70.711 0.000
.y2 0.990 0.014 70.711 0.000
same values in MPlus (LinearMedData.csv is the data generated in lavaan)
DATA: FILE IS LinearMedData.csv ;
VARIABLE: NAMES sort x y1 y2;
USEVARIABLES x y1 y2;
ANALYSIS: ESTIMATOR = ML;
MODEL: y1 on x;
y2 on y1;
y2 on x;
OUTPUT: SAMPSTAT
STDYX
CINTERVAL
TECH3;
Results
Estimate S.E. Est./S.E. P-Value
Y1 ON
X 0.548 0.010 55.611 0.000
Y2 ON
Y1 0.456 0.010 45.378 0.000
X 0.244 0.011 21.542 0.000
Intercepts
Y1 0.002 0.010 0.230 0.818
Y2 -0.011 0.010 -1.080 0.280
Residual Variances
Y1 0.981 0.014 70.709 0.000
Y2 0.990 0.014 70.710 0.000
2. Simplest mediation with binary mediator
#Generated data
N <- 10000
x <- rnorm(N)
y1dummy <- inv.logit(0.55* x) > runif(N)
#I have to do a trick to create a dummy variable depending on other when generating dataset cause lavaan cannot work still with dummy, binary or categorical variables. In words of Terrence: It will be probit by default (logit unavailable) if you declare the outcome as categorical using the ordered= argument
y2 <- 0.24*x + 0.47*y1 + rnorm(N)
LogitMedData <- data.frame(x, y1dummy,y2)
write.xlsx(LogitMedData, "C:/Users/gaiarrido/Desktop/LogitMedData.xlsx") # write sheet
#Data analysis
LogitMedMod <- 'y1dummy~a*x
y2~b*x+ c*y1dummy
'
fitLogitMedMod <- sem(LogitMedMod, data = LogitMedData, estimator="WLSMV" , ordered="y1dummy")
summary(fitLogitMedMod)
Regressions:
Estimate Std.Err z-value P(>|z|)
y1dummy ~
x (a) 0.345 0.013 25.990 0.000
y2 ~
x (b) 0.498 0.012 41.974 0.000
y1dummy (c) -0.013 0.014 -0.940 0.347
Same two problems here
1) I have to say that is ordered, not dummy cause lavaan cannot work still with dummy
2) I cannot use estimator MLR
In MPlus
DATA: FILE IS LogitMedData.csv ;
VARIABLE: NAMES sort x y1dummy y2;
USEVARIABLES x y1dummy y2;
CATEGORICAL ARE y1dummy;
ANALYSIS: TYPE = random;
ALGORITHM = INTEGRATION;
ESTIMATOR = MLR;
MODEL: y1dummy on x;
y2 on y1dummy;
y2 on x;
OUTPUT: SAMPSTAT
STDYX
CINTERVAL
TECH3;
Results
Estimate S.E. Est./S.E. P-Value
Y1DUMMY ON
X 0.558 0.022 25.433 0.000
Y2 ON
Y1DUMMY -0.020 0.023 -0.898 0.369
X 0.496 0.011 43.987 0.000
3. Simplest mediation with binary DV
#Generated data
N <- 10000
x <- rnorm(N)
y1 <- 0.55*x + rnorm(N)
y2dummy <- inv.logit(0.24*x+0.47*y1)> runif(N) #In the forum told me that this is the good option
#I have to do a trick to create a dummy variable depending on other when generating dataset cause lavaan cannot work still with dummy, binary or categorical variables. In words of Terrence: It will be probit by default (logit unavailable) if you declare the outcome as categorical using the ordered= argument
LogitDvData <- data.frame(x, y1,y2dummy)
write.xlsx(LogitDvData, "C:/Users/gaiarrido/Desktop/LogitDvData.xlsx") # write sheet
#Data analysis
LogitDvMod <- 'y1~a*x
y2dummy~b*x+ c*y1
'
fitLogitDvMod <- sem(LogitDvMod, data = LogitDvData, estimator="WLSMV" , ordered="y2dummy")
summary(fitLogitDvMod)
Regressions:
Estimate Std.Err z-value P(>|z|)
y1 ~
x (a) 0.548 0.010 55.807 0.000
y2dummy ~
x (b) 0.148 0.014 10.340 0.000
y1 (c) 0.267 0.012 22.401 0.000
Same two problems here
3) I have to say that is ordered, not dummy cause lavaan cannot work still with dummy
4) I cannot use estimator MLR
In MPlus
DATA: FILE IS LogitDvData.csv ;
VARIABLE: NAMES sort x y1 y2dummy;
USEVARIABLES x y1 y2dummy;
CATEGORICAL ARE y2dummy;
ANALYSIS: TYPE = random;
ALGORITHM = INTEGRATION;
ESTIMATOR = MLR;
MODEL: y1 on x;
y2dummy on y1;
y2dummy on x;
OUTPUT: SAMPSTAT
STDYX
CINTERVAL
TECH3;
Results are good
Estimate S.E. Est./S.E. P-Value
Y1 ON
X 0.548 0.010 55.402 0.000
Y2DUMMY ON
Y1 0.452 0.022 20.323 0.000
X 0.251 0.024 10.338 0.000
I have to do a trick to create a dummy variable depending on other when generating dataset cause lavaan cannot work still with dummy, binary or categorical variables.
In words of Terrence: It will be probit by default (logit unavailable) if you declare the outcome as categorical using the ordered= argument
1) I have to say that is ordered, not dummy cause lavaan cannot work still with dummy
2) I cannot use estimator MLR
N <- 10000
x <- rnorm(N)
y1dummy <- inv.logit(0.55* x) > runif(N)
y2 <- 0.24*x
+ 0.47*y1dummy + rnorm(N)
LogitMedMod <- 'y1dummy~a*x
y2~b*x+ c*y1dummy
'
fitLogitMedMod <- sem(LogitMedMod, data = LogitMedData, ordered="y1dummy")
Regressions: Estimate Std.Err z-value P(>|z|)
y1dummy ~
x (a) 0.355 0.013 26.719 0.000
y2 ~
x (b) 0.215 0.011 19.284 0.000
y1dummy (c) 0.275 0.013 21.205 0.000In MPlus
DATA: FILE IS LogitMedData.csv ;
VARIABLE: NAMES sort x y1dummy y2;
USEVARIABLES x y1dummy y2;
CATEGORICAL ARE y1dummy;
ANALYSIS: TYPE = random;
ALGORITHM = INTEGRATION;
ESTIMATOR = MLR;
MODEL: y1dummy on x;
y2 on y1dummy;
y2 on x;
Results
Estimate S.E. Est./S.E. P-Value
Y1DUMMY ON
X 0.576 0.022 25.973 0.000
Y2 ON
X 0.253 0.010 24.416 0.000
Y1DUMMY 0.446
0.021
21.234 0.000
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to lav...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
My suggestion:a_logit := a*1.7c_logit := c*1.7
y1dummy <- pnorm(0.55* x) > runif(N)