lavaan
if (!require(lavaan)) install.packages("lavaan")
Loading required package: lavaan
This is lavaan 0.5-23.1097
lavaan is BETA software! Please report any bugs.
library(lavaan)
These data were adapted from Lesa's dissertation work in which 152 adults age 63–87 years were measured on visual impairment (distance acuity and five degrees of contrast sensitivity), processing speed, divided visual attention, and selective visual attention (as measured by the Useful Field of View subtests for each), attentional search efficiency (DriverScan), and simulator driving impairment (as measured by six driving performance indicators).
Hoffman, L., Yang, X., Bovaird, J. A., & Embretson, S. E. (2006). Measuring attention in older adults: Development and psychometric evaluation of DriverScan. Educational and Psychological Measurement, 66, 984-1000.
Hoffman, L., McDowd, J. M., Atchley, P., & Dubinsky R. A. (2005). The role of visual attention in predicting driving impairment in older adults. Psychology and Aging, 20(4), 610-622.
This example will demonstrate how to estimate structural equation models. Please see the Mplus example for more complex tasks that can be implemented in R, but that take extra effort.
driverData = read.csv(file = "driverscanSEM.csv", na.strings = c("-9999", "-9999.00"),
col.names = c("PartID", "sex", "age75", "lncs15", "lncs3", "lncs6",
"lncs12", "lncs18", "far", "lnps", "lnda", "lnsa", "Dscan",
"lane", "da_task", "crash", "stop", "speed", "time"))
We will begin by fitting single-factor measurement models for each latent factor. This is because we need to ensure each factor fits individually as this cuts down on the dimensions of model modification when building the final SEM.
visImpareSyntax = "
vision =~ far + lncs3 + lncs6 + lncs12 + lncs15 + lncs18
"
visImpareEstimates = cfa(model = visImpareSyntax, data = driverData, estimator = "MLR", mimic = "mplus", std.lv = FALSE)
summary(visImpareEstimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 41 iterations
Number of observations 151
Number of missing patterns 1
Estimator ML Robust
Minimum Function Test Statistic 16.588 15.108
Degrees of freedom 9 9
P-value (Chi-square) 0.056 0.088
Scaling correction factor 1.098
for the Yuan-Bentler correction (Mplus variant)
Model test baseline model:
Minimum Function Test Statistic 280.933 267.801
Degrees of freedom 15 15
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.971 0.976
Tucker-Lewis Index (TLI) 0.952 0.960
Robust Comparative Fit Index (CFI) 0.975
Robust Tucker-Lewis Index (TLI) 0.958
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -738.876 -738.876
Scaling correction factor 1.127
for the MLR correction
Loglikelihood unrestricted model (H1) -730.582 -730.582
Scaling correction factor 1.118
for the MLR correction
Number of free parameters 18 18
Akaike (AIC) 1513.753 1513.753
Bayesian (BIC) 1568.064 1568.064
Sample-size adjusted Bayesian (BIC) 1511.096 1511.096
Root Mean Square Error of Approximation:
RMSEA 0.075 0.067
90 Percent Confidence Interval 0.000 0.130 0.000 0.122
P-value RMSEA <= 0.05 0.207 0.271
Robust RMSEA 0.070
90 Percent Confidence Interval 0.000 0.130
Standardized Root Mean Square Residual:
SRMR 0.040 0.040
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision =~
far 1.000 0.485 0.588
lncs3 0.572 0.110 5.187 0.000 0.277 0.651
lncs6 0.739 0.127 5.834 0.000 0.359 0.684
lncs12 1.285 0.205 6.257 0.000 0.624 0.767
lncs15 0.476 0.096 4.988 0.000 0.231 0.536
lncs18 1.460 0.219 6.659 0.000 0.709 0.713
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 3.033 0.067 45.164 0.000 3.033 3.675
.lncs3 -3.943 0.035 -113.729 0.000 -3.943 -9.255
.lncs6 -3.734 0.043 -87.592 0.000 -3.734 -7.128
.lncs12 -2.365 0.066 -35.753 0.000 -2.365 -2.910
.lncs15 -3.703 0.035 -105.362 0.000 -3.703 -8.574
.lncs18 -1.415 0.081 -17.504 0.000 -1.415 -1.424
vision 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 0.445 0.053 8.436 0.000 0.445 0.654
.lncs3 0.105 0.014 7.446 0.000 0.105 0.576
.lncs6 0.146 0.028 5.210 0.000 0.146 0.532
.lncs12 0.272 0.046 5.958 0.000 0.272 0.412
.lncs15 0.133 0.018 7.461 0.000 0.133 0.713
.lncs18 0.485 0.062 7.858 0.000 0.485 0.491
vision 0.236 0.067 3.500 0.000 1.000 1.000
R-Square:
Estimate
far 0.346
lncs3 0.424
lncs6 0.468
lncs12 0.588
lncs15 0.287
lncs18 0.509
driveImpareSyntax = "
driving =~ crash + da_task + lane + stop + speed + time
speed ~~ time
"
driveImpareEstimates = cfa(model = driveImpareSyntax, data = driverData, estimator = "MLR", mimic = "mplus", std.lv = FALSE)
lavaan WARNING: some cases are empty and will be ignored:
25 31 33 45 55 56 57 60 66 75 85 87 93 96 98 116 129 141 142 147
summary(driveImpareEstimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 63 iterations
Used Total
Number of observations 131 151
Number of missing patterns 1
Estimator ML Robust
Minimum Function Test Statistic 12.588 12.748
Degrees of freedom 8 8
P-value (Chi-square) 0.127 0.121
Scaling correction factor 0.987
for the Yuan-Bentler correction (Mplus variant)
Model test baseline model:
Minimum Function Test Statistic 80.217 74.767
Degrees of freedom 15 15
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.930 0.921
Tucker-Lewis Index (TLI) 0.868 0.851
Robust Comparative Fit Index (CFI) 0.927
Robust Tucker-Lewis Index (TLI) 0.863
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -38.306 -38.306
Scaling correction factor 1.157
for the MLR correction
Loglikelihood unrestricted model (H1) -32.012 -32.012
Scaling correction factor 1.107
for the MLR correction
Number of free parameters 19 19
Akaike (AIC) 114.612 114.612
Bayesian (BIC) 169.241 169.241
Sample-size adjusted Bayesian (BIC) 109.146 109.146
Root Mean Square Error of Approximation:
RMSEA 0.066 0.067
90 Percent Confidence Interval 0.000 0.132 0.000 0.134
P-value RMSEA <= 0.05 0.303 0.294
Robust RMSEA 0.067
90 Percent Confidence Interval 0.000 0.132
Standardized Root Mean Square Residual:
SRMR 0.053 0.053
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
driving =~
crash 1.000 0.390 0.647
da_task 0.179 0.080 2.238 0.025 0.070 0.475
lane 0.148 0.059 2.505 0.012 0.058 0.330
stop 0.353 0.170 2.078 0.038 0.138 0.313
speed 0.416 0.142 2.928 0.003 0.163 0.333
time 0.052 0.047 1.100 0.271 0.020 0.194
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.speed ~~
.time -0.023 0.004 -5.396 0.000 -0.023 -0.495
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.crash 0.866 0.053 16.418 0.000 0.866 1.434
.da_task 0.257 0.013 20.015 0.000 0.257 1.749
.lane 0.817 0.015 53.151 0.000 0.817 4.644
.stop 0.206 0.038 5.354 0.000 0.206 0.468
.speed 0.840 0.043 19.725 0.000 0.840 1.723
.time 3.146 0.009 346.449 0.000 3.146 30.269
driving 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.crash 0.212 0.056 3.776 0.000 0.212 0.582
.da_task 0.017 0.004 4.461 0.000 0.017 0.774
.lane 0.028 0.004 6.603 0.000 0.028 0.891
.stop 0.175 0.031 5.577 0.000 0.175 0.902
.speed 0.211 0.029 7.410 0.000 0.211 0.889
.time 0.010 0.001 8.484 0.000 0.010 0.963
driving 0.152 0.062 2.440 0.015 1.000 1.000
R-Square:
Estimate
crash 0.418
da_task 0.226
lane 0.109
stop 0.098
speed 0.111
time 0.037
attentionSyntax = "
attn =~ lnda + lnsa + Dscan
"
attentionEstimates = cfa(model = attentionSyntax, data = driverData, estimator = "MLR", mimic = "mplus", std.lv = FALSE)
summary(attentionEstimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 20 iterations
Number of observations 151
Number of missing patterns 1
Estimator ML Robust
Minimum Function Test Statistic 0.000 0.000
Degrees of freedom 0 0
Scaling correction factor NA
for the Yuan-Bentler correction (Mplus variant)
Model test baseline model:
Minimum Function Test Statistic 123.518 128.472
Degrees of freedom 3 3
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 1.000 1.000
Tucker-Lewis Index (TLI) 1.000 1.000
Robust Comparative Fit Index (CFI) 1.000
Robust Tucker-Lewis Index (TLI) 1.000
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -455.435 -455.435
Loglikelihood unrestricted model (H1) -455.435 -455.435
Number of free parameters 9 9
Akaike (AIC) 928.871 928.871
Bayesian (BIC) 956.026 956.026
Sample-size adjusted Bayesian (BIC) 927.542 927.542
Root Mean Square Error of Approximation:
RMSEA 0.000 0.000
90 Percent Confidence Interval 0.000 0.000 0.000 0.000
P-value RMSEA <= 0.05 NA NA
Robust RMSEA 0.000
90 Percent Confidence Interval 0.000 0.000
Standardized Root Mean Square Residual:
SRMR 0.000 0.000
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
attn =~
lnda 1.000 0.674 0.688
lnsa 0.507 0.069 7.390 0.000 0.342 0.763
Dscan 1.102 0.139 7.940 0.000 0.743 0.749
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.lnda 4.348 0.080 54.528 0.000 4.348 4.437
.lnsa 5.581 0.036 153.267 0.000 5.581 12.473
.Dscan -0.004 0.081 -0.043 0.965 -0.004 -0.004
attn 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.lnda 0.505 0.068 7.431 0.000 0.505 0.526
.lnsa 0.084 0.017 4.894 0.000 0.084 0.417
.Dscan 0.433 0.085 5.085 0.000 0.433 0.440
attn 0.455 0.089 5.102 0.000 1.000 1.000
R-Square:
Estimate
lnda 0.474
lnsa 0.583
Dscan 0.560
Now we are ready to test the model of interest. We'll begin with a saturated structural model, meaning this fits as well as a model that has undirected paths between variables.
semSyntax1 = "
#measurement models
vision =~ far + lncs3 + lncs6 + lncs12 + lncs15 + lncs18
driving =~ crash + da_task + lane + stop + speed + time
attn =~ lnda + lnsa + Dscan
speed ~~ time
#structural model regressions
vision ~ (Age1)*age75
attn ~ (Age2)*age75 + vision
lnps ~ (Age3)*age75 + vision
driving ~ age75 + (Vis1)*vision + (Speed1)*lnps + (Attn1)*attn
#residual covariance
attn ~~ lnps
#indirect effects
AgeVis := Age1*Vis1
AgeSpeed := Age3*Speed1
AgeAttn := Age2*Attn1
"
semEstimates1 = cfa(model = semSyntax1, data = driverData, estimator = "MLR", mimic = "mplus", std.lv = FALSE)
summary(semEstimates1, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 115 iterations
Number of observations 151
Number of missing patterns 2
Estimator ML Robust
Minimum Function Test Statistic 143.265 142.176
Degrees of freedom 110 110
P-value (Chi-square) 0.018 0.021
Scaling correction factor 1.008
for the Yuan-Bentler correction (Mplus variant)
Model test baseline model:
Minimum Function Test Statistic 685.761 669.927
Degrees of freedom 136 136
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.939 0.940
Tucker-Lewis Index (TLI) 0.925 0.925
Robust Comparative Fit Index (CFI) 0.941
Robust Tucker-Lewis Index (TLI) 0.927
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -1741.590 -1741.590
Scaling correction factor 1.107
for the MLR correction
Loglikelihood unrestricted model (H1) -1669.958 -1669.958
Scaling correction factor 1.042
for the MLR correction
Number of free parameters 58 58
Akaike (AIC) 3599.181 3599.181
Bayesian (BIC) 3774.183 3774.183
Sample-size adjusted Bayesian (BIC) 3590.619 3590.619
Root Mean Square Error of Approximation:
RMSEA 0.045 0.044
90 Percent Confidence Interval 0.020 0.064 0.018 0.063
P-value RMSEA <= 0.05 0.650 0.672
Robust RMSEA 0.044
90 Percent Confidence Interval 0.018 0.064
Standardized Root Mean Square Residual:
SRMR 0.062 0.062
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision =~
far 1.000 0.492 0.596
lncs3 0.563 0.107 5.244 0.000 0.277 0.650
lncs6 0.735 0.127 5.792 0.000 0.362 0.691
lncs12 1.253 0.201 6.237 0.000 0.617 0.759
lncs15 0.462 0.093 4.990 0.000 0.227 0.526
lncs18 1.449 0.215 6.729 0.000 0.713 0.718
driving =~
crash 1.000 0.343 0.570
da_task 0.200 0.068 2.952 0.003 0.069 0.468
lane 0.159 0.067 2.366 0.018 0.055 0.311
stop 0.386 0.167 2.307 0.021 0.132 0.301
speed 0.406 0.167 2.432 0.015 0.140 0.286
time 0.099 0.055 1.794 0.073 0.034 0.329
attn =~
lnda 1.000 0.671 0.685
lnsa 0.483 0.061 7.953 0.000 0.324 0.724
Dscan 1.163 0.161 7.239 0.000 0.781 0.787
Regressions:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision ~
age75 (Age1) 0.026 0.011 2.370 0.018 0.052 0.238
attn ~
age75 (Age2) 0.060 0.014 4.272 0.000 0.090 0.407
vision 0.284 0.136 2.091 0.037 0.208 0.208
lnps ~
age75 (Age3) 0.008 0.008 0.957 0.338 0.008 0.073
vision 0.160 0.098 1.628 0.104 0.079 0.158
driving ~
age75 -0.000 0.012 -0.001 0.999 -0.000 -0.000
vision (Vis1) -0.073 0.105 -0.697 0.486 -0.105 -0.105
lnps (Spd1) 0.113 0.083 1.373 0.170 0.330 0.165
attn (Att1) 0.356 0.124 2.875 0.004 0.696 0.696
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.speed ~~
.time -0.025 0.005 -5.424 0.000 -0.025 -0.541
.attn ~~
.lnps 0.063 0.027 2.318 0.020 0.109 0.222
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 3.029 0.065 46.355 0.000 3.029 3.671
.lncs3 -3.945 0.034 -114.729 0.000 -3.945 -9.260
.lncs6 -3.737 0.042 -88.577 0.000 -3.737 -7.134
.lncs12 -2.370 0.065 -36.693 0.000 -2.370 -2.915
.lncs15 -3.705 0.035 -105.010 0.000 -3.705 -8.578
.lncs18 -1.421 0.079 -18.050 0.000 -1.421 -1.430
.crash 0.550 0.235 2.336 0.020 0.550 0.913
.da_task 0.193 0.051 3.767 0.000 0.193 1.320
.lane 0.766 0.037 20.440 0.000 0.766 4.361
.stop 0.084 0.095 0.890 0.374 0.084 0.191
.speed 0.712 0.104 6.855 0.000 0.712 1.461
.time 3.114 0.032 96.579 0.000 3.114 29.991
.lnda 4.338 0.076 56.829 0.000 4.338 4.427
.lnsa 5.576 0.035 160.434 0.000 5.576 12.462
.Dscan -0.015 0.074 -0.206 0.837 -0.015 -0.015
.lnps 2.800 0.040 69.459 0.000 2.800 5.601
.vision 0.000 0.000 0.000
.driving 0.000 0.000 0.000
.attn 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 0.439 0.052 8.411 0.000 0.439 0.644
.lncs3 0.105 0.014 7.462 0.000 0.105 0.578
.lncs6 0.144 0.028 5.064 0.000 0.144 0.523
.lncs12 0.280 0.045 6.167 0.000 0.280 0.424
.lncs15 0.135 0.018 7.371 0.000 0.135 0.723
.lncs18 0.479 0.063 7.610 0.000 0.479 0.485
.crash 0.245 0.043 5.672 0.000 0.245 0.675
.da_task 0.017 0.003 5.557 0.000 0.017 0.781
.lane 0.028 0.004 6.758 0.000 0.028 0.903
.stop 0.176 0.033 5.369 0.000 0.176 0.910
.speed 0.218 0.026 8.283 0.000 0.218 0.918
.time 0.010 0.001 7.777 0.000 0.010 0.892
.lnda 0.510 0.068 7.499 0.000 0.510 0.531
.lnsa 0.095 0.016 6.086 0.000 0.095 0.475
.Dscan 0.376 0.064 5.888 0.000 0.376 0.381
.lnps 0.241 0.033 7.243 0.000 0.241 0.964
.vision 0.228 0.062 3.698 0.000 0.943 0.943
.driving 0.055 0.031 1.758 0.079 0.467 0.467
.attn 0.338 0.077 4.366 0.000 0.750 0.750
R-Square:
Estimate
far 0.356
lncs3 0.422
lncs6 0.477
lncs12 0.576
lncs15 0.277
lncs18 0.515
crash 0.325
da_task 0.219
lane 0.097
stop 0.090
speed 0.082
time 0.108
lnda 0.469
lnsa 0.525
Dscan 0.619
lnps 0.036
vision 0.057
driving 0.533
attn 0.250
Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
AgeVis -0.002 0.003 -0.709 0.479 -0.005 -0.025
AgeSpeed 0.001 0.001 0.742 0.458 0.003 0.012
AgeAttn 0.021 0.009 2.458 0.014 0.062 0.283
To show the bootstrap standard errors, we use the following syntax:
semEstimates1B = cfa(model = semSyntax1, data = driverData, estimator = "ML", mimic = "mplus", std.lv = FALSE, se = "bootstrap")
lavaan WARNING: the covariance matrix of the residuals of the observed
variables (theta) is not positive definite;
use inspect(fit,"theta") to investigate.lavaan WARNING: some estimated lv variances are negativelavaan WARNING: model has NOT converged!lavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated ov variances are negativelavaan WARNING: model has NOT converged!lavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: model has NOT converged!lavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated ov variances are negativelavaan WARNING: the covariance matrix of the residuals of the observed
variables (theta) is not positive definite;
use inspect(fit,"theta") to investigate.lavaan WARNING: some estimated ov variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: the covariance matrix of the residuals of the observed
variables (theta) is not positive definite;
use inspect(fit,"theta") to investigate.lavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: model has NOT converged!lavaan WARNING: some estimated ov variances are negativelavaan WARNING: some estimated ov variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: the covariance matrix of the residuals of the observed
variables (theta) is not positive definite;
use inspect(fit,"theta") to investigate.lavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated ov variances are negativelavaan WARNING: only 996 bootstrap draws were successful
summary(semEstimates1B, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 115 iterations
Number of observations 151
Number of missing patterns 2
Estimator ML
Minimum Function Test Statistic 143.265
Degrees of freedom 110
P-value (Chi-square) 0.018
Model test baseline model:
Minimum Function Test Statistic 685.761
Degrees of freedom 136
P-value 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.939
Tucker-Lewis Index (TLI) 0.925
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -1741.590
Loglikelihood unrestricted model (H1) -1669.958
Number of free parameters 58
Akaike (AIC) 3599.181
Bayesian (BIC) 3774.183
Sample-size adjusted Bayesian (BIC) 3590.619
Root Mean Square Error of Approximation:
RMSEA 0.045
90 Percent Confidence Interval 0.020 0.064
P-value RMSEA <= 0.05 0.650
Standardized Root Mean Square Residual:
SRMR 0.062
Parameter Estimates:
Information Observed
Standard Errors Bootstrap
Number of requested bootstrap draws 1000
Number of successful bootstrap draws 996
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision =~
far 1.000 0.492 0.596
lncs3 0.563 0.117 4.824 0.000 0.277 0.650
lncs6 0.735 0.136 5.420 0.000 0.362 0.691
lncs12 1.253 0.200 6.269 0.000 0.617 0.759
lncs15 0.462 0.100 4.620 0.000 0.227 0.526
lncs18 1.449 0.237 6.114 0.000 0.713 0.718
driving =~
crash 1.000 0.343 0.570
da_task 0.200 0.303 0.660 0.509 0.069 0.468
lane 0.159 0.232 0.687 0.492 0.055 0.311
stop 0.386 0.416 0.928 0.354 0.132 0.301
speed 0.406 2.072 0.196 0.844 0.140 0.286
time 0.099 11.193 0.009 0.993 0.034 0.329
attn =~
lnda 1.000 0.671 0.685
lnsa 0.483 0.062 7.832 0.000 0.324 0.724
Dscan 1.163 0.174 6.690 0.000 0.781 0.787
Regressions:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision ~
age75 (Age1) 0.026 0.011 2.381 0.017 0.052 0.238
attn ~
age75 (Age2) 0.060 0.014 4.244 0.000 0.090 0.407
vision 0.284 0.150 1.895 0.058 0.208 0.208
lnps ~
age75 (Age3) 0.008 0.008 0.965 0.335 0.008 0.073
vision 0.160 0.106 1.511 0.131 0.079 0.158
driving ~
age75 -0.000 0.012 -0.001 0.999 -0.000 -0.000
vision (Vis1) -0.073 0.119 -0.616 0.538 -0.105 -0.105
lnps (Spd1) 0.113 0.088 1.283 0.200 0.330 0.165
attn (Att1) 0.356 0.133 2.674 0.007 0.696 0.696
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.speed ~~
.time -0.025 0.005 -4.925 0.000 -0.025 -0.541
.attn ~~
.lnps 0.063 0.028 2.292 0.022 0.109 0.222
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 3.029 0.067 45.257 0.000 3.029 3.671
.lncs3 -3.945 0.035 -113.424 0.000 -3.945 -9.260
.lncs6 -3.737 0.043 -87.564 0.000 -3.737 -7.134
.lncs12 -2.370 0.063 -37.428 0.000 -2.370 -2.915
.lncs15 -3.705 0.035 -104.460 0.000 -3.705 -8.578
.lncs18 -1.421 0.078 -18.230 0.000 -1.421 -1.430
.crash 0.550 0.250 2.202 0.028 0.550 0.913
.da_task 0.193 0.052 3.700 0.000 0.193 1.320
.lane 0.766 0.044 17.552 0.000 0.766 4.361
.stop 0.084 0.111 0.758 0.449 0.084 0.191
.speed 0.712 0.119 6.007 0.000 0.712 1.461
.time 3.114 0.039 80.169 0.000 3.114 29.991
.lnda 4.338 0.078 55.296 0.000 4.338 4.427
.lnsa 5.576 0.034 162.065 0.000 5.576 12.462
.Dscan -0.015 0.074 -0.207 0.836 -0.015 -0.015
.lnps 2.800 0.040 69.700 0.000 2.800 5.601
.vision 0.000 0.000 0.000
.driving 0.000 0.000 0.000
.attn 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 0.439 0.053 8.354 0.000 0.439 0.644
.lncs3 0.105 0.014 7.314 0.000 0.105 0.578
.lncs6 0.144 0.027 5.333 0.000 0.144 0.523
.lncs12 0.280 0.047 5.921 0.000 0.280 0.424
.lncs15 0.135 0.018 7.299 0.000 0.135 0.723
.lncs18 0.479 0.065 7.387 0.000 0.479 0.485
.crash 0.245 0.046 5.347 0.000 0.245 0.675
.da_task 0.017 0.003 5.457 0.000 0.017 0.781
.lane 0.028 0.004 6.737 0.000 0.028 0.903
.stop 0.176 0.033 5.352 0.000 0.176 0.910
.speed 0.218 0.028 7.844 0.000 0.218 0.918
.time 0.010 0.019 0.510 0.610 0.010 0.892
.lnda 0.510 0.071 7.228 0.000 0.510 0.531
.lnsa 0.095 0.016 6.087 0.000 0.095 0.475
.Dscan 0.376 0.066 5.686 0.000 0.376 0.381
.lnps 0.241 0.034 7.135 0.000 0.241 0.964
.vision 0.228 0.061 3.756 0.000 0.943 0.943
.driving 0.055 0.032 1.701 0.089 0.467 0.467
.attn 0.338 0.074 4.573 0.000 0.750 0.750
R-Square:
Estimate
far 0.356
lncs3 0.422
lncs6 0.477
lncs12 0.576
lncs15 0.277
lncs18 0.515
crash 0.325
da_task 0.219
lane 0.097
stop 0.090
speed 0.082
time 0.108
lnda 0.469
lnsa 0.525
Dscan 0.619
lnps 0.036
vision 0.057
driving 0.533
attn 0.250
Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
AgeVis -0.002 0.003 -0.594 0.552 -0.005 -0.025
AgeSpeed 0.001 0.001 0.627 0.531 0.003 0.012
AgeAttn 0.021 0.010 2.197 0.028 0.062 0.283
Next, we will remove the non-significant paths of age and vision on driving and see if the model fits as well as the last one.
semSyntax2 = "
#measurement models
vision =~ far + lncs3 + lncs6 + lncs12 + lncs15 + lncs18
driving =~ crash + da_task + lane + stop + speed + time
attn =~ lnda + lnsa + Dscan
speed ~~ time
#structural model regressions
vision ~ (Age1)*age75
attn ~ (Age2)*age75 + vision
lnps ~ (Age3)*age75 + vision
driving ~ (Speed1)*lnps + (Attn1)*attn
#residual covariance
attn ~~ lnps
#indirect effects
AgeSpeed := Age3*Speed1
AgeAttn := Age2*Attn1
"
semEstimates2 = cfa(model = semSyntax2, data = driverData, estimator = "MLR", mimic = "mplus", std.lv = FALSE)
summary(semEstimates2, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
anova(semEstimates1, semEstimates2)
To show the bootstrap standard errors, we use the following syntax:
semEstimates2B = cfa(model = semSyntax2, data = driverData, estimator = "ML", mimic = "mplus", std.lv = FALSE, se = "bootstrap")
lavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: some estimated lv variances are negativelavaan WARNING: model has NOT converged!lavaan WARNING: only 999 bootstrap draws were successful
summary(semEstimates2B, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 107 iterations
Number of observations 151
Number of missing patterns 2
Estimator ML
Minimum Function Test Statistic 143.952
Degrees of freedom 112
P-value (Chi-square) 0.023
Model test baseline model:
Minimum Function Test Statistic 685.761
Degrees of freedom 136
P-value 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.942
Tucker-Lewis Index (TLI) 0.929
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -1741.933
Loglikelihood unrestricted model (H1) -1669.958
Number of free parameters 56
Akaike (AIC) 3595.867
Bayesian (BIC) 3764.835
Sample-size adjusted Bayesian (BIC) 3587.600
Root Mean Square Error of Approximation:
RMSEA 0.043
90 Percent Confidence Interval 0.017 0.063
P-value RMSEA <= 0.05 0.688
Standardized Root Mean Square Residual:
SRMR 0.062
Parameter Estimates:
Information Observed
Standard Errors Bootstrap
Number of requested bootstrap draws 1000
Number of successful bootstrap draws 999
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision =~
far 1.000 0.492 0.597
lncs3 0.563 0.110 5.110 0.000 0.277 0.651
lncs6 0.735 0.132 5.571 0.000 0.362 0.690
lncs12 1.255 0.215 5.827 0.000 0.618 0.760
lncs15 0.463 0.095 4.850 0.000 0.228 0.528
lncs18 1.442 0.236 6.117 0.000 0.710 0.715
driving =~
crash 1.000 0.343 0.570
da_task 0.205 0.074 2.780 0.005 0.070 0.480
lane 0.164 0.074 2.203 0.028 0.056 0.320
stop 0.395 0.185 2.138 0.032 0.136 0.308
speed 0.412 0.177 2.328 0.020 0.142 0.290
time 0.094 0.054 1.732 0.083 0.032 0.311
attn =~
lnda 1.000 0.672 0.686
lnsa 0.484 0.065 7.418 0.000 0.325 0.726
Dscan 1.161 0.187 6.195 0.000 0.781 0.786
Regressions:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
vision ~
age75 (Age1) 0.026 0.011 2.385 0.017 0.052 0.237
attn ~
age75 (Age2) 0.060 0.015 4.148 0.000 0.090 0.408
vision 0.271 0.146 1.850 0.064 0.198 0.198
lnps ~
age75 (Age3) 0.008 0.008 0.956 0.339 0.008 0.073
vision 0.160 0.102 1.563 0.118 0.079 0.158
driving ~
lnps (Spd1) 0.103 0.084 1.229 0.219 0.300 0.150
attn (Att1) 0.338 0.086 3.944 0.000 0.662 0.662
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.speed ~~
.time -0.025 0.005 -5.418 0.000 -0.025 -0.534
.attn ~~
.lnps 0.064 0.027 2.390 0.017 0.109 0.223
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 3.029 0.063 47.874 0.000 3.029 3.671
.lncs3 -3.945 0.035 -113.433 0.000 -3.945 -9.260
.lncs6 -3.737 0.043 -87.689 0.000 -3.737 -7.134
.lncs12 -2.370 0.065 -36.242 0.000 -2.370 -2.915
.lncs15 -3.705 0.034 -109.268 0.000 -3.705 -8.578
.lncs18 -1.421 0.078 -18.183 0.000 -1.421 -1.430
.crash 0.579 0.237 2.444 0.015 0.579 0.962
.da_task 0.198 0.053 3.760 0.000 0.198 1.351
.lane 0.770 0.041 18.653 0.000 0.770 4.380
.stop 0.093 0.104 0.890 0.373 0.093 0.211
.speed 0.722 0.104 6.956 0.000 0.722 1.482
.time 3.119 0.030 102.629 0.000 3.119 30.029
.lnda 4.338 0.076 57.389 0.000 4.338 4.427
.lnsa 5.576 0.035 158.644 0.000 5.576 12.462
.Dscan -0.015 0.074 -0.207 0.836 -0.015 -0.015
.lnps 2.800 0.040 69.528 0.000 2.800 5.601
.vision 0.000 0.000 0.000
.driving 0.000 0.000 0.000
.attn 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.far 0.439 0.051 8.617 0.000 0.439 0.644
.lncs3 0.105 0.014 7.252 0.000 0.105 0.577
.lncs6 0.144 0.028 5.089 0.000 0.144 0.524
.lncs12 0.279 0.048 5.873 0.000 0.279 0.422
.lncs15 0.135 0.019 7.254 0.000 0.135 0.721
.lncs18 0.483 0.066 7.367 0.000 0.483 0.489
.crash 0.245 0.040 6.130 0.000 0.245 0.675
.da_task 0.017 0.003 5.370 0.000 0.017 0.769
.lane 0.028 0.004 6.917 0.000 0.028 0.898
.stop 0.176 0.032 5.567 0.000 0.176 0.905
.speed 0.218 0.027 8.060 0.000 0.218 0.916
.time 0.010 0.001 8.299 0.000 0.010 0.903
.lnda 0.509 0.070 7.305 0.000 0.509 0.530
.lnsa 0.095 0.016 5.792 0.000 0.095 0.472
.Dscan 0.376 0.069 5.492 0.000 0.376 0.382
.lnps 0.241 0.033 7.349 0.000 0.241 0.964
.vision 0.229 0.062 3.679 0.000 0.944 0.944
.driving 0.057 0.031 1.837 0.066 0.486 0.486
.attn 0.341 0.079 4.346 0.000 0.756 0.756
R-Square:
Estimate
far 0.356
lncs3 0.423
lncs6 0.476
lncs12 0.578
lncs15 0.279
lncs18 0.511
crash 0.325
da_task 0.231
lane 0.102
stop 0.095
speed 0.084
time 0.097
lnda 0.470
lnsa 0.528
Dscan 0.618
lnps 0.036
vision 0.056
driving 0.514
attn 0.244
Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
AgeSpeed 0.001 0.001 0.616 0.538 0.002 0.011
AgeAttn 0.020 0.006 3.419 0.001 0.059 0.270
Did constraining these two paths to 0 make the model worse? Rescaled −2ΔLL(2) = 0.462, p = .79, so no.
This is the appropriate way to test a structural model, whose job is to reproduce the covariance among the latent factors and any observed predictors (but not among any observed predictors themselves).
Relying on good global model fit (which will mostly reflect the measurement models) is not sufficient to say a structural model fits.
library("semPlot")
semPaths(semEstimates2, intercept = FALSE, whatLabel = "std",
residuals = TRUE, exoCov = FALSE)