Estimate interaction effects in structural equation models (SEMs) using a twostep procedure
Source:R/twostep.R
twostep.RdEstimate an interaction model using a twostep procedure. For the PI approaches, the lavaan::sam function
is used to optimize the models, instead of lavaan::sem. Note that the product indicators are still used,
and not the newly developed SAM approach to estimate latent interactions. For the DA approaches (LMS and QML)
the measurement model is estimated using a CFA (lavaan::cfa). The structural model is estimated using
modsem_da, where the estimates in the measurement model are fixed, based on the CFA estimates.
Note that standard errors are uncorrected (i.e., naive), and do not account for the uncertainty in the CFA estimates.
NOTE, this is an experimental feature!
Arguments
- model.syntax
lavaansyntax- data
dataframe
- method
method to use:
"dblcent"double centering approach (passed to
lavaan)."ca"constrained approach (passed to
lavaan)."rca"residual centering approach (passed to
lavaan)."uca"unconstrained approach (passed to
lavaan)."pind"prod ind approach, with no constraints or centering (passed to
lavaan)."lms"latent moderated structural equations (not passed to
lavaan)."qml"quasi maximum likelihood estimation (not passed to
lavaan)."custom"use parameters specified in the function call (passed to
lavaan).
- ...
arguments passed to other functions depending on the method (see
modsem_piandmodsem_da)
Examples
library(modsem)
m1 <- '
# Outer Model
X =~ x1 + x2 +x3
Y =~ y1 + y2 + y3
Z =~ z1 + z2 + z3
# Inner model
Y ~ X + Z + X:Z
'
est_dblcent <- twostep(m1, oneInt, method = "dblcent")
summary(est_dblcent)
#> Estimating baseline model (H0)
#> modsem (version 1.0.24, approach = dblcent):
#>
#> Interaction Model Fit Measures (H1):
#> Loglikelihood NA
#> Akaike (AIC) NA
#> Bayesian (BIC) NA
#> Chi-square NA
#> Degrees of Freedom NA
#> P-value (Chi-square) NA
#> RMSEA NA
#> CFI NA
#> SRMR NA
#>
#> Fit Measures for Baseline Model (H0):
#> Loglikelihood NA
#> Akaike (AIC) NA
#> Bayesian (BIC) NA
#> Chi-square NA
#> Degrees of Freedom NA
#> P-value (Chi-square) NA
#> RMSEA NA
#> CFI NA
#> SRMR NA
#>
#> Comparative Fit to H0 (LRT test):
#> Chi-square diff 833.597
#> Degrees of freedom diff 1
#> P-value (LRT) 0.000
#>
#> R-Squared Interaction Model (H1):
#> Y 0.601
#> R-Squared Baseline Model (H0):
#> Y 0.395
#> R-Squared Change (H1 - H0):
#> Y 0.206
#>
#> This is lavaan 0.6-20 -- using the SAM approach to SEM
#>
#> SAM method LOCAL
#> Mapping matrix M method ML
#> Number of measurement blocks 4
#> Estimator measurement part ML
#> Estimator structural part ML
#>
#> Number of observations 2000
#>
#> Summary Information Measurement + Structural:
#>
#> Block Latent Nind Chisq Df
#> 1 X 3 0.000 0
#> 2 XZ 9 4.051 9
#> 3 Y 3 0.000 0
#> 4 Z 3 0.000 0
#>
#> Model-based reliability latent variables:
#>
#> X Y Z XZ
#> 0.938 0.975 0.939 0.888
#>
#> Summary Information Structural part:
#>
#> chisq df cfi rmsea srmr
#> 0 0 1 0 0
#>
#> Parameter Estimates:
#>
#> Standard errors Twostep
#> Information Expected
#> Information saturated (h1) model Structured
#>
#> Regressions:
#> Estimate Std.Err z-value P(>|z|)
#> Y ~
#> X 0.675 0.027 25.356 0.000
#> Z 0.560 0.026 21.598 0.000
#> XZ 0.703 0.027 26.277 0.000
#>
#> Covariances:
#> Estimate Std.Err z-value P(>|z|)
#> X ~~
#> Z 0.201 0.024 8.270 0.000
#> XZ 0.016 0.025 0.636 0.525
#> Z ~~
#> XZ 0.062 0.025 2.448 0.014
#>
#> Variances:
#> Estimate Std.Err z-value P(>|z|)
#> X 0.981 0.037 26.833 0.000
#> .Y 0.994 0.038 25.958 0.000
#> Z 1.018 0.038 26.862 0.000
#> XZ 1.043 0.044 23.826 0.000
#>
# \dontrun{
est_lms <- twostep(m1, oneInt, method = "lms")
summary(est_lms)
#>
#> modsem (1.0.24) ended normally after 8 iterations
#>
#> Estimator LMS
#> Optimization method EMA-NLMINB
#> Number of model parameters 5
#>
#> Number of observations 2000
#>
#> Loglikelihood and Information Criteria:
#> Loglikelihood -17493.83
#> Akaike (AIC) 34997.66
#> Bayesian (BIC) 35025.67
#>
#> Numerical Integration:
#> Points of integration (per dim) 24
#> Dimensions 1
#> Total points of integration 24
#>
#> Fit Measures for Baseline Model (H0):
#> Standard
#> Chi-square 17.52
#> Degrees of Freedom (Chi-square) 50
#> P-value (Chi-square) 1.000
#> RMSEA 0.000
#>
#> Loglikelihood -17831.87
#> Akaike (AIC) 35671.75
#> Bayesian (BIC) 35694.15
#>
#> Comparative Fit to H0 (LRT test):
#> Loglikelihood change 338.04
#> Difference test (D) 676.09
#> Degrees of freedom (D) 1
#> P-value (D) 0.000
#>
#> R-Squared Interaction Model (H1):
#> Y 0.599
#> R-Squared Baseline Model (H0):
#> Y 0.395
#> R-Squared Change (H1 - H0):
#> Y 0.204
#>
#> Parameter Estimates:
#> Coefficients unstandardized
#> Information observed
#> Standard errors standard
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 1.000
#> x2 0.804 0.013 63.471 0.000
#> x3 0.916 0.014 67.011 0.000
#> Z =~
#> z1 1.000
#> z2 0.811 0.013 64.623 0.000
#> z3 0.882 0.013 67.005 0.000
#> Y =~
#> y1 1.000
#> y2 0.798 0.007 107.625 0.000
#> y3 0.898 0.008 112.184 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.674 0.026 25.860 0.000
#> Z 0.570 0.026 22.210 0.000
#> X:Z 0.719 0.026 27.191 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 1.023 0.024 42.827 0.000
#> .x2 1.215 0.020 60.907 0.000
#> .x3 0.919 0.022 41.421 0.000
#> .z1 1.011 0.024 41.562 0.000
#> .z2 1.206 0.020 59.256 0.000
#> .z3 0.916 0.022 42.049 0.000
#> .y1 1.180 0.036 32.446 0.000
#> .y2 1.335 0.029 45.255 0.000
#> .y3 1.083 0.033 32.833 0.000
#> .Y -0.144 0.024 -5.875 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.201 0.024 8.271 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 0.160 0.009 17.721 0.000
#> .x2 0.162 0.007 22.912 0.000
#> .x3 0.162 0.008 20.010 0.000
#> .z1 0.168 0.009 18.087 0.000
#> .z2 0.159 0.007 22.272 0.000
#> .z3 0.157 0.008 20.253 0.000
#> .y1 0.155 0.009 17.245 0.000
#> .y2 0.155 0.007 22.466 0.000
#> .y3 0.167 0.008 20.658 0.000
#> X 0.981 0.036 26.884 0.000
#> Z 1.016 0.038 26.846 0.000
#> .Y 0.982 0.037 26.831 0.000
#>
est_qml <- twostep(m1, oneInt, method = "qml")
summary(est_qml)
#>
#> modsem (1.0.24) ended normally after 5 iterations
#>
#> Estimator QML
#> Optimization method NLMINB
#> Number of model parameters 5
#>
#> Number of observations 2000
#>
#> Loglikelihood and Information Criteria:
#> Loglikelihood -17493.88
#> Akaike (AIC) 34997.75
#> Bayesian (BIC) 35025.76
#>
#> Fit Measures for Baseline Model (H0):
#> Standard
#> Chi-square 17.52
#> Degrees of Freedom (Chi-square) 50
#> P-value (Chi-square) 1.000
#> RMSEA 0.000
#>
#> Loglikelihood -17831.87
#> Akaike (AIC) 35671.75
#> Bayesian (BIC) 35694.15
#>
#> Comparative Fit to H0 (LRT test):
#> Loglikelihood change 338.00
#> Difference test (D) 676.00
#> Degrees of freedom (D) 1
#> P-value (D) 0.000
#>
#> R-Squared Interaction Model (H1):
#> Y 0.599
#> R-Squared Baseline Model (H0):
#> Y 0.395
#> R-Squared Change (H1 - H0):
#> Y 0.204
#>
#> Parameter Estimates:
#> Coefficients unstandardized
#> Information observed
#> Standard errors standard
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 1.000
#> x2 0.804 0.013 63.471 0.000
#> x3 0.916 0.014 67.011 0.000
#> Z =~
#> z1 1.000
#> z2 0.811 0.013 64.623 0.000
#> z3 0.882 0.013 67.005 0.000
#> Y =~
#> y1 1.000
#> y2 0.798 0.007 107.625 0.000
#> y3 0.898 0.008 112.184 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.674 0.026 25.856 0.000
#> Z 0.570 0.026 22.204 0.000
#> X:Z 0.720 0.026 27.190 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 1.023 0.024 42.827 0.000
#> .x2 1.215 0.020 60.907 0.000
#> .x3 0.919 0.022 41.421 0.000
#> .z1 1.011 0.024 41.562 0.000
#> .z2 1.206 0.020 59.256 0.000
#> .z3 0.916 0.022 42.049 0.000
#> .y1 1.180 0.036 32.446 0.000
#> .y2 1.335 0.029 45.255 0.000
#> .y3 1.083 0.033 32.833 0.000
#> .Y -0.144 0.024 -5.866 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.201 0.024 8.271 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 0.160 0.009 17.721 0.000
#> .x2 0.162 0.007 22.912 0.000
#> .x3 0.162 0.008 20.010 0.000
#> .z1 0.168 0.009 18.087 0.000
#> .z2 0.159 0.007 22.272 0.000
#> .z3 0.157 0.008 20.253 0.000
#> .y1 0.155 0.009 17.245 0.000
#> .y2 0.155 0.007 22.466 0.000
#> .y3 0.167 0.008 20.658 0.000
#> X 0.981 0.036 26.884 0.000
#> Z 1.016 0.038 26.846 0.000
#> .Y 0.982 0.037 26.784 0.000
#>
# }
tpb_uk <- "
# Outer Model (Based on Hagger et al., 2007)
ATT =~ att1 + att2 + att3 + att4 + att5
SN =~ sn1 + sn2 + sn3
PBC =~ pbc1 + pbc2 + pbc3 + pbc4
INT =~ int1 + int2 + int3 + int4
BEH =~ beh1 + beh2 + beh3
# Inner Model (Based on Steinmetz et al., 2011)
# Causal Relationsships
INT ~ ATT + SN + PBC
BEH ~ INT + PBC
BEH ~ INT:PBC
"
uk_dblcent <- twostep(tpb_uk, TPB_UK, method = "dblcent")
summary(uk_dblcent)
#> Estimating baseline model (H0)
#> modsem (version 1.0.24, approach = dblcent):
#>
#> Interaction Model Fit Measures (H1):
#> Loglikelihood NA
#> Akaike (AIC) NA
#> Bayesian (BIC) NA
#> Chi-square NA
#> Degrees of Freedom NA
#> P-value (Chi-square) NA
#> RMSEA NA
#> CFI NA
#> SRMR NA
#>
#> Fit Measures for Baseline Model (H0):
#> Loglikelihood NA
#> Akaike (AIC) NA
#> Bayesian (BIC) NA
#> Chi-square NA
#> Degrees of Freedom NA
#> P-value (Chi-square) NA
#> RMSEA NA
#> CFI NA
#> SRMR NA
#>
#> Comparative Fit to H0 (LRT test):
#> Chi-square diff 370.823
#> Degrees of freedom diff 1
#> P-value (LRT) 0.000
#>
#> R-Squared Interaction Model (H1):
#> INT 0.911
#> BEH 0.856
#> R-Squared Baseline Model (H0):
#> INT 0.911
#> BEH 0.828
#> R-Squared Change (H1 - H0):
#> INT -0.000
#> BEH 0.028
#>
#> This is lavaan 0.6-20 -- using the SAM approach to SEM
#>
#> SAM method LOCAL
#> Mapping matrix M method ML
#> Number of measurement blocks 6
#> Estimator measurement part ML
#> Estimator structural part ML
#>
#> Number of observations 1894
#>
#> Summary Information Measurement + Structural:
#>
#> Block Latent Nind Chisq Df
#> 1 ATT 5 1017.132 5
#> 2 BEH 3 0.000 0
#> 3 INT 4 25.912 2
#> 4 INTPBC 16 797.363 56
#> 5 PBC 4 581.968 2
#> 6 SN 3 0.000 0
#>
#> Model-based reliability latent variables:
#>
#> ATT SN PBC INT BEH INTPBC
#> 0.966 0.949 0.932 0.983 0.963 0.901
#>
#> Summary Information Structural part:
#>
#> chisq df cfi rmsea srmr
#> 160.532 3 0.981 0.167 0.019
#>
#> Parameter Estimates:
#>
#> Standard errors Twostep
#> Information Expected
#> Information saturated (h1) model Structured
#>
#> Regressions:
#> Estimate Std.Err z-value P(>|z|)
#> INT ~
#> ATT 0.279 0.032 8.767 0.000
#> SN -0.010 0.021 -0.452 0.651
#> PBC 2.845 0.210 13.525 0.000
#> BEH ~
#> INT 0.621 0.040 15.515 0.000
#> PBC 0.751 0.155 4.851 0.000
#> INTPBC 0.282 0.027 10.495 0.000
#>
#> Covariances:
#> Estimate Std.Err z-value P(>|z|)
#> ATT ~~
#> SN 1.388 0.069 20.071 0.000
#> PBC 0.744 0.058 12.840 0.000
#> INTPBC -0.087 0.044 -1.961 0.050
#> SN ~~
#> PBC 0.528 0.042 12.425 0.000
#> INTPBC -0.162 0.041 -3.937 0.000
#> PBC ~~
#> INTPBC -0.036 0.017 -2.178 0.029
#>
#> Variances:
#> Estimate Std.Err z-value P(>|z|)
#> ATT 2.314 0.118 19.584 0.000
#> SN 1.797 0.090 19.914 0.000
#> PBC 0.314 0.043 7.296 0.000
#> .INT 0.377 0.023 16.655 0.000
#> .BEH 0.485 0.024 20.281 0.000
#> INTPBC 1.374 0.208 6.617 0.000
#>
# \dontrun{
uk_qml <- twostep(tpb_uk, TPB_UK, method = "qml")
uk_lms <- twostep(tpb_uk, TPB_UK, method = "lms", nodes = 32, adaptive.quad = TRUE)
summary(uk_lms)
#>
#> modsem (1.0.24) ended normally after 43 iterations
#>
#> Estimator LMS
#> Optimization method EMA-NLMINB
#> Number of model parameters 9
#>
#> Number of observations 1894
#>
#> Loglikelihood and Information Criteria:
#> Loglikelihood -53954.91
#> Akaike (AIC) 107927.81
#> Bayesian (BIC) 107977.73
#>
#> Numerical Integration:
#> Points of integration (per dim) 32
#> Dimensions 1
#> Total points of integration 32
#>
#> Fit Measures for Baseline Model (H0):
#> Standard
#> Chi-square 3197.83
#> Degrees of Freedom (Chi-square) 201
#> P-value (Chi-square) 0.000
#> RMSEA 0.089
#>
#> Loglikelihood -54095.10
#> Akaike (AIC) 108206.21
#> Bayesian (BIC) 108250.58
#>
#> Comparative Fit to H0 (LRT test):
#> Loglikelihood change 140.20
#> Difference test (D) 280.40
#> Degrees of freedom (D) 1
#> P-value (D) 0.000
#>
#> R-Squared Interaction Model (H1):
#> INT 0.913
#> BEH 0.873
#> R-Squared Baseline Model (H0):
#> INT 0.914
#> BEH 0.829
#> R-Squared Change (H1 - H0):
#> INT -0.001
#> BEH 0.044
#>
#> Parameter Estimates:
#> Coefficients unstandardized
#> Information observed
#> Standard errors standard
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> ATT =~
#> att1 1.000
#> att2 1.328 0.028 47.040 0.000
#> att3 1.395 0.029 47.622 0.000
#> att4 0.920 0.028 33.193 0.000
#> att5 0.991 0.029 33.979 0.000
#> SN =~
#> sn1 1.000
#> sn2 1.242 0.027 46.850 0.000
#> sn3 1.290 0.027 48.376 0.000
#> PBC =~
#> pbc1 1.000
#> pbc2 3.924 0.276 14.203 0.000
#> pbc3 3.625 0.256 14.145 0.000
#> pbc4 1.313 0.115 11.423 0.000
#> INT =~
#> int1 1.000
#> int2 1.041 0.010 107.761 0.000
#> int3 1.020 0.010 101.151 0.000
#> int4 1.029 0.010 103.973 0.000
#> BEH =~
#> beh1 1.000
#> beh2 1.206 0.017 72.475 0.000
#> beh3 1.233 0.016 77.746 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> INT ~
#> ATT 0.288 0.028 10.109 0.000
#> SN -0.025 0.020 -1.252 0.210
#> PBC 3.032 0.086 35.421 0.000
#> BEH ~
#> PBC 0.648 0.153 4.232 0.000
#> INT 0.660 0.039 17.091 0.000
#> INT:PBC 0.381 0.022 17.320 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .pbc1 5.783 0.038 151.255 0.000
#> .pbc2 4.084 0.050 81.490 0.000
#> .pbc3 3.837 0.048 80.077 0.000
#> .pbc4 5.378 0.039 137.171 0.000
#> .att1 4.359 0.046 95.460 0.000
#> .att2 3.835 0.048 79.202 0.000
#> .att3 3.797 0.050 75.442 0.000
#> .att4 4.963 0.045 111.421 0.000
#> .att5 4.986 0.047 105.961 0.000
#> .sn1 5.012 0.040 126.687 0.000
#> .sn2 4.397 0.041 106.010 0.000
#> .sn3 4.427 0.042 106.443 0.000
#> .int1 3.948 0.050 79.120 0.000
#> .int2 3.848 0.051 76.048 0.000
#> .int3 3.845 0.050 76.706 0.000
#> .int4 3.885 0.050 77.256 0.000
#> .beh1 2.781 0.047 59.462 0.000
#> .beh2 3.341 0.054 61.721 0.000
#> .beh3 3.401 0.054 62.846 0.000
#> .BEH -0.395 0.029 -13.571 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> ATT ~~
#> SN 1.394 0.069 20.132 0.000
#> PBC ~~
#> ATT 0.700 0.057 12.377 0.000
#> SN 0.502 0.042 12.031 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .pbc1 2.489 0.081 30.634 0.000
#> .pbc2 0.453 0.026 17.338 0.000
#> .pbc3 0.677 0.029 23.492 0.000
#> .pbc4 2.429 0.080 30.526 0.000
#> .att1 1.657 0.056 29.364 0.000
#> .att2 0.398 0.021 19.111 0.000
#> .att3 0.340 0.021 16.280 0.000
#> .att4 1.818 0.061 29.691 0.000
#> .att5 1.941 0.066 29.594 0.000
#> .sn1 1.153 0.041 28.171 0.000
#> .sn2 0.465 0.026 17.754 0.000
#> .sn3 0.263 0.024 10.795 0.000
#> .int1 0.459 0.017 26.531 0.000
#> .int2 0.237 0.011 21.744 0.000
#> .int3 0.325 0.013 24.469 0.000
#> .int4 0.286 0.012 23.466 0.000
#> .beh1 0.744 0.029 25.981 0.000
#> .beh2 0.609 0.028 21.782 0.000
#> .beh3 0.379 0.023 16.268 0.000
#> ATT 2.293 0.118 19.476 0.000
#> SN 1.811 0.090 20.069 0.000
#> PBC 0.279 0.040 6.962 0.000
#> .INT 0.369 0.020 18.354 0.000
#> .BEH 0.464 0.021 22.009 0.000
#>
# }