processR
packageYou have to install the developemental version of package processR from github.
if(!require(devtools)) install.packages("devtools")
devtools::install_github("cardiomoon/processR",dependencies = FALSE)
require(processR)
require(lavaan)
labels=list(X="estress",M="affect",Y="withdraw")
covar=list(names=c("ese","sex","tenure"),site=list(c("M","Y"),c("Mi","Y"),c("Mi","Y")))
pmacroModel(4,labels=labels,covar=covar)
statisticalDiagram(4,labels=labels,covar=covar)
equations=tripleEquation(labels=labels,covar=covar,mode=1)
cat(equations)
affect ~ estress + ese + sex + tenure
withdraw ~ affect+estress + ese + sex + tenure
fit=eq2fit(equations,data=estress)
modelsSummaryTable(fit,labels=labels)
Consequent | |||||||||
M(affect) | Y(withdraw) | ||||||||
Antecedent | Coef | SE | t | p | Coef | SE | t | p | |
X(estress) | 0.159 | 0.030 | 5.361 | <.001 | -0.094 | 0.053 | -1.775 | .077 | |
ese | -0.155 | 0.044 | -3.489 | .001 | -0.212 | 0.076 | -2.777 | .006 | |
sex | 0.015 | 0.086 | 0.173 | .863 | 0.127 | 0.144 | 0.884 | .378 | |
tenure | -0.011 | 0.006 | -1.723 | .086 | -0.002 | 0.011 | -0.194 | .846 | |
M(affect) | 0.707 | 0.105 | 6.742 | <.001 | |||||
Constant | 1.785 | 0.308 | 5.803 | <.001 | 2.746 | 0.550 | 4.991 | <.001 | |
Observations | 262 | 262 | |||||||
R2 | 0.163 | 0.206 | |||||||
Adjusted R2 | 0.150 | 0.190 | |||||||
Residual SE | 0.667 ( df = 257) | 1.122 ( df = 256) | |||||||
F statistic | F(4,257) = 12.523, p < .001 | F(5,256) = 13.282, p < .001 |
model=tripleEquation(labels=labels,covar=covar)
cat(model)
affect ~ a1*estress + f1*ese + f2*sex + f3*tenure
withdraw ~ b1*affect+c1*estress + g1*ese + g2*sex + g3*tenure
indirect :=(a1)*(b1)
direct :=c1
total := direct + indirect
prop.mediated := indirect / total
semfit=sem(model=model,data=estress)
summary(semfit)
lavaan 0.6-3 ended normally after 26 iterations
Optimization method NLMINB
Number of free parameters 11
Number of observations 262
Estimator ML
Model Fit Test Statistic 0.000
Degrees of freedom 0
Minimum Function Value 0.0000000000000
Parameter Estimates:
Information Expected
Information saturated (h1) model Structured
Standard Errors Standard
Regressions:
Estimate Std.Err z-value P(>|z|)
affect ~
estress (a1) 0.159 0.029 5.413 0.000
ese (f1) -0.155 0.044 -3.523 0.000
sex (f2) 0.015 0.085 0.174 0.862
tenure (f3) -0.011 0.006 -1.739 0.082
withdraw ~
affect (b1) 0.707 0.104 6.821 0.000
estress (c1) -0.094 0.052 -1.796 0.073
ese (g1) -0.212 0.076 -2.809 0.005
sex (g2) 0.127 0.142 0.894 0.371
tenure (g3) -0.002 0.011 -0.196 0.844
Variances:
Estimate Std.Err z-value P(>|z|)
.affect 0.437 0.038 11.446 0.000
.withdraw 1.230 0.107 11.446 0.000
Defined Parameters:
Estimate Std.Err z-value P(>|z|)
indirect 0.113 0.027 4.240 0.000
direct -0.094 0.052 -1.796 0.073
total 0.019 0.054 0.357 0.721
prop.mediated 5.888 16.127 0.365 0.715
estimatesTable2(semfit,vanilla=TRUE)
Variables | Predictors | B | SE | z | p | β |
affect | estress | 0.16 | 0.03 | 5.41 | < 0.001 | 0.31 |
affect | ese | -0.15 | 0.04 | -3.52 | < 0.001 | -0.20 |
affect | sex | 0.01 | 0.08 | 0.17 | 0.862 | 0.01 |
affect | tenure | -0.01 | 0.01 | -1.74 | 0.082 | -0.10 |
withdraw | affect | 0.71 | 0.10 | 6.82 | < 0.001 | 0.41 |
withdraw | estress | -0.09 | 0.05 | -1.80 | 0.073 | -0.11 |
withdraw | ese | -0.21 | 0.08 | -2.81 | 0.005 | -0.16 |
withdraw | sex | 0.13 | 0.14 | 0.89 | 0.371 | 0.05 |
withdraw | tenure | -0.00 | 0.01 | -0.20 | 0.844 | -0.01 |
medSummaryTable(semfit)
Effect | Equation | estimate | 95% CI | p |
indirect | (a1)*(b1) | 0.113 | (0.061 to 0.165) | <.001 |
direct | c1 | -0.094 | (-0.196 to 0.009) | .073 |
total | direct+indirect | 0.019 | (-0.086 to 0.124) | .721 |
prop.mediated | indirect/total | 5.888 | (-25.721 to 37.497) | .715 |
statisticalDiagram(4,labels=labels,fit=semfit,covar=covar,whatLabel="est")
statisticalDiagram(4,labels=labels,fit=semfit,whatLabel="est")
covar1=list(names=c("sex"),site=list(c("Mi","Y")))
statisticalDiagram(4,labels=labels,fit=semfit,covar=covar1,whatLabel="est")