# NOT RUN {
#To calculate power for mediation based on Monte Carlo simulation when Sobel test is used:
#To specify the model
demo ="
y ~ cp*x + start(0)*x + b*m + start(0.39)* m
m ~ a*x + start(0.39)*x
x ~~ start(1)*x
m ~~ start(1)*m
y ~~ start(1)*y
"
#To specify the indirect effects
mediation = "
ab := a*b
abc:= a*b + cp
"
#To calculate power for mediation using regular standard errors
sobel.regular = wp.mc.sem.basic(model=demo, indirect=mediation, nobs=100, nrep=1000,
parallel="snow", skewness=c(0, 0, 1.3), kurtosis=c(0,0,10), ovnames=c("x","m","y"))
#To calculate power for mediation using robust standard errors
sobel.robust = wp.mc.sem.basic(model=demo, indirect=mediation, nobs=100, nrep=1000,
parallel="snow", skewness=c(0, 0, 1.3), kurtosis=c(0,0,10), ovnames=c("x","m","y"), se="robust")
#To print the power for mediation based on Sobel test using regular standard errors:
summary(sobel.regular)
# Basic information:
#
# Esimation method ML
# Standard error standard
# Number of requested replications 1000
# Number of successful replications 1000
#
# True Estimate MSE SD Power Coverage
# Regressions:
# y ~
# x (cp) 0.000 0.003 0.106 0.107 0.045 0.955
# m (b) 0.390 0.387 0.099 0.113 0.965 0.919
# m ~
# x (a) 0.390 0.389 0.100 0.101 0.976 0.953
# Variances:
# x 1.000 0.995 0.141 0.139 1.000 0.936
# m 1.000 0.981 0.139 0.137 1.000 0.923
# y 1.000 0.968 0.137 0.330 1.000 0.560
#
# Indirect/Mediation effects:
# ab 0.152 0.150 0.056 0.060 0.886 0.928
# abc 0.152 0.153 0.106 0.109 0.305 0.948
#To print the power analysis results for mediation based on Sobel test using robust standard errors:
summary(sobel.robust)
# Basic information:
#
# Esimation method ML
# Standard error robust.sem
# Number of requested replications 1000
# Number of successful replications 1000
#
# True Estimate MSE SD Power Coverage
# Regressions:
# y ~
# x (cp) 0.000 -0.003 0.106 0.113 0.055 0.945
# m (b) 0.390 0.398 0.111 0.119 0.972 0.927
# m ~
# x (a) 0.390 0.389 0.099 0.101 0.974 0.939
#
# Intercepts:
# y 0.000 0.000 0.100 0.104 0.058 0.942
# m 0.000 0.000 0.100 0.105 0.054 0.946
# x 0.000 -0.004 0.100 0.104 0.066 0.934
#
# Variances:
# x 1.000 0.991 0.138 0.140 1.000 0.930
# m 1.000 0.976 0.135 0.135 1.000 0.915
# y 1.000 1.002 0.281 0.365 0.981 0.805
#
# Indirect/Mediation effects:
# ab 0.152 0.156 0.060 0.064 0.870 0.900
# abc 0.152 0.153 0.108 0.117 0.303 0.936
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab