Estimate interaction effects in structural equation models (SEMs) using a twostep procedure
twostep.Rd
Estimate 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
lavaan
syntax- 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_pi
andmodsem_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.11, 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-19 -- 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 Y 3 0.000 0
#> 3 Z 3 0.000 0
#> 4 XZ 9 4.051 9
#>
#> 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 (version 1.0.11):
#>
#> Estimator LMS
#> Optimization method EMA-NLMINB
#> Number of observations 2000
#> Number of iterations 8
#> Loglikelihood -14662.52
#> Akaike (AIC) 29335.04
#> Bayesian (BIC) 29363.04
#>
#> Numerical Integration:
#> Points of integration (per dim) 24
#> Dimensions 1
#> Total points of integration 24
#>
#> Fit Measures for Baseline Model (H0):
#> Loglikelihood -17831.87
#> Akaike (AIC) 35671.75
#> Bayesian (BIC) 35694.15
#> Chi-square 17.52
#> Degrees of Freedom (Chi-square) 50
#> P-value (Chi-square) 1.000
#> RMSEA 0.000
#>
#> Comparative Fit to H0 (LRT test):
#> Loglikelihood change 3169.36
#> Difference test (D) 6338.71
#> 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.47 0.000
#> x3 0.916 0.014 67.01 0.000
#> Z =~
#> z1 1.000
#> z2 0.811 0.013 64.62 0.000
#> z3 0.882 0.013 67.00 0.000
#> Y =~
#> y1 1.000
#> y2 0.798 0.007 107.62 0.000
#> y3 0.898 0.008 112.18 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.674 0.026 25.86 0.000
#> Z 0.570 0.026 22.21 0.000
#> X:Z 0.719 0.026 27.19 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 1.023 0.024 42.83 0.000
#> .x2 1.215 0.020 60.91 0.000
#> .x3 0.919 0.022 41.42 0.000
#> .z1 1.011 0.024 41.56 0.000
#> .z2 1.206 0.020 59.26 0.000
#> .z3 0.916 0.022 42.05 0.000
#> .y1 1.180 0.036 32.45 0.000
#> .y2 1.335 0.029 45.26 0.000
#> .y3 1.083 0.033 32.83 0.000
#> .Y -0.144 0.024 -5.88 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.201 0.024 8.27 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 0.160 0.009 17.72 0.000
#> .x2 0.162 0.007 22.91 0.000
#> .x3 0.162 0.008 20.01 0.000
#> .z1 0.168 0.009 18.09 0.000
#> .z2 0.159 0.007 22.27 0.000
#> .z3 0.157 0.008 20.25 0.000
#> .y1 0.155 0.009 17.25 0.000
#> .y2 0.155 0.007 22.47 0.000
#> .y3 0.167 0.008 20.66 0.000
#> X 0.981 0.036 26.88 0.000
#> Z 1.016 0.038 26.85 0.000
#> .Y 0.982 0.037 26.83 0.000
#>
est_qml <- twostep(m1, oneInt, method = "qml")
summary(est_qml)
#>
#> modsem (version 1.0.11):
#>
#> Estimator QML
#> Optimization method NLMINB
#> Number of observations 2000
#> Number of iterations 9
#> Loglikelihood -17501.85
#> Akaike (AIC) 35013.7
#> Bayesian (BIC) 35041.71
#>
#> Fit Measures for Baseline Model (H0):
#> Loglikelihood -17831.87
#> Akaike (AIC) 35671.75
#> Bayesian (BIC) 35694.15
#> Chi-square 17.52
#> Degrees of Freedom (Chi-square) 50
#> P-value (Chi-square) 1.000
#> RMSEA 0.000
#>
#> Comparative Fit to H0 (LRT test):
#> Loglikelihood change 330.02
#> Difference test (D) 660.05
#> Degrees of freedom (D) 1
#> P-value (D) 0.000
#>
#> R-Squared Interaction Model (H1):
#> Y 0.617
#> R-Squared Baseline Model (H0):
#> Y 0.395
#> R-Squared Change (H1 - H0):
#> Y 0.221
#>
#> 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.47 0.000
#> x3 0.916 0.014 67.01 0.000
#> Z =~
#> z1 1.000
#> z2 0.811 0.013 64.62 0.000
#> z3 0.882 0.013 67.00 0.000
#> Y =~
#> y1 1.000
#> y2 0.798 0.007 107.62 0.000
#> y3 0.898 0.008 112.18 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.674 0.026 26.15 0.000
#> Z 0.566 0.025 22.35 0.000
#> X:Z 0.714 0.026 27.96 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 1.023 0.024 42.83 0.000
#> .x2 1.215 0.020 60.91 0.000
#> .x3 0.919 0.022 41.42 0.000
#> .z1 1.011 0.024 41.56 0.000
#> .z2 1.206 0.020 59.26 0.000
#> .z3 0.916 0.022 42.05 0.000
#> .y1 1.180 0.036 32.45 0.000
#> .y2 1.335 0.029 45.26 0.000
#> .y3 1.083 0.033 32.83 0.000
#> .Y -0.144 0.025 -5.83 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.201 0.024 8.27 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .x1 0.160 0.009 17.72 0.000
#> .x2 0.162 0.007 22.91 0.000
#> .x3 0.162 0.008 20.01 0.000
#> .z1 0.168 0.009 18.09 0.000
#> .z2 0.159 0.007 22.27 0.000
#> .z3 0.157 0.008 20.25 0.000
#> .y1 0.155 0.009 17.25 0.000
#> .y2 0.155 0.007 22.47 0.000
#> .y3 0.167 0.008 20.66 0.000
#> X 0.981 0.036 26.88 0.000
#> Z 1.016 0.038 26.85 0.000
#> .Y 0.904 0.038 23.77 0.000
#>
# }
tpb_uk <- "
# Outer Model (Based on Hagger et al., 2007)
ATT =~ att3 + att2 + att1 + att4
SN =~ sn4 + sn2 + sn3 + sn1
PBC =~ pbc2 + pbc1 + pbc3 + pbc4
INT =~ int2 + int1 + int3 + int4
BEH =~ beh3 + beh2 + beh1 + beh4
# 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.11, 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 303.820
#> Degrees of freedom diff 1
#> P-value (LRT) 0.000
#>
#> R-Squared Interaction Model (H1):
#> INT 0.896
#> BEH 0.896
#> R-Squared Baseline Model (H0):
#> INT 0.896
#> BEH 0.867
#> R-Squared Change (H1 - H0):
#> INT -0.000
#> BEH 0.029
#>
#> This is lavaan 0.6-19 -- 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 1169
#>
#> Summary Information Measurement + Structural:
#>
#> Block Latent Nind Chisq Df
#> 1 ATT 4 0.043 2
#> 2 SN 4 1191.318 2
#> 3 PBC 4 778.543 2
#> 4 INT 4 31.869 2
#> 5 BEH 4 934.696 2
#> 6 INTPBC 16 1055.748 56
#>
#> Model-based reliability latent variables:
#>
#> ATT SN PBC INT BEH INTPBC
#> 0.972 0.954 0.939 0.985 0.963 0.912
#>
#> Summary Information Structural part:
#>
#> chisq df cfi rmsea srmr
#> 88.274 3 0.984 0.156 0.018
#>
#> Parameter Estimates:
#>
#> Standard errors Twostep
#> Information Expected
#> Information saturated (h1) model Structured
#>
#> Regressions:
#> Estimate Std.Err z-value P(>|z|)
#> INT ~
#> ATT -0.023 0.028 -0.836 0.403
#> SN -0.066 0.024 -2.795 0.005
#> PBC 1.062 0.032 33.220 0.000
#> BEH ~
#> INT 0.681 0.047 14.440 0.000
#> PBC 0.303 0.051 5.983 0.000
#> INTPBC 0.152 0.011 13.426 0.000
#>
#> Covariances:
#> Estimate Std.Err z-value P(>|z|)
#> ATT ~~
#> SN 2.278 0.128 17.735 0.000
#> PBC 3.639 0.177 20.550 0.000
#> INTPBC 0.141 0.178 0.791 0.429
#> SN ~~
#> PBC 2.217 0.129 17.191 0.000
#> INTPBC -0.101 0.142 -0.710 0.478
#> PBC ~~
#> INTPBC 0.245 0.177 1.384 0.166
#>
#> Variances:
#> Estimate Std.Err z-value P(>|z|)
#> ATT 4.463 0.198 22.584 0.000
#> SN 2.803 0.130 21.586 0.000
#> PBC 4.338 0.212 20.507 0.000
#> .INT 0.514 0.039 13.142 0.000
#> .BEH 0.550 0.036 15.187 0.000
#> INTPBC 7.363 0.552 13.350 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 (version 1.0.11):
#>
#> Estimator LMS
#> Optimization method EMA-NLMINB
#> Number of observations 1169
#> Number of iterations 33
#> Loglikelihood -33402.21
#> Akaike (AIC) 66822.42
#> Bayesian (BIC) 66868
#>
#> Numerical Integration:
#> Points of integration (per dim) 32
#> Dimensions 1
#> Total points of integration 32
#>
#> Fit Measures for Baseline Model (H0):
#> Loglikelihood -35523.38
#> Akaike (AIC) 71062.75
#> Bayesian (BIC) 71103.26
#> Chi-square 5520.02
#> Degrees of Freedom (Chi-square) 222
#> P-value (Chi-square) 0.000
#> RMSEA 0.143
#>
#> Comparative Fit to H0 (LRT test):
#> Loglikelihood change 2121.16
#> Difference test (D) 4242.33
#> Degrees of freedom (D) 1
#> P-value (D) 0.000
#>
#> R-Squared Interaction Model (H1):
#> INT 0.898
#> BEH 0.921
#> R-Squared Baseline Model (H0):
#> INT 0.896
#> BEH 0.868
#> R-Squared Change (H1 - H0):
#> INT 0.002
#> BEH 0.053
#>
#> Parameter Estimates:
#> Coefficients unstandardized
#> Information observed
#> Standard errors standard
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> PBC =~
#> pbc2 1.000
#> pbc1 0.853 0.020 42.45 0.000
#> pbc3 0.936 0.017 55.72 0.000
#> pbc4 0.813 0.020 40.99 0.000
#> ATT =~
#> att3 1.000
#> att2 0.964 0.011 84.97 0.000
#> att1 0.812 0.017 47.13 0.000
#> att4 0.869 0.019 45.69 0.000
#> SN =~
#> sn4 1.000
#> sn2 1.314 0.039 33.49 0.000
#> sn3 1.352 0.040 34.14 0.000
#> sn1 1.000 0.039 25.87 0.000
#> INT =~
#> int2 1.000
#> int1 0.970 0.011 92.00 0.000
#> int3 0.984 0.010 98.96 0.000
#> int4 0.992 0.009 104.92 0.000
#> BEH =~
#> beh3 1.000
#> beh2 0.983 0.013 76.14 0.000
#> beh1 0.812 0.019 43.19 0.000
#> beh4 0.802 0.019 42.04 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> INT ~
#> PBC 1.024 0.030 34.71 0.000
#> ATT -0.047 0.025 -1.86 0.063
#> SN 0.047 0.031 1.51 0.130
#> BEH ~
#> PBC 0.386 0.049 7.87 0.000
#> INT 0.604 0.046 13.21 0.000
#> PBC:INT 0.140 0.008 18.06 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .pbc2 4.019 0.066 61.07 0.000
#> .pbc1 3.986 0.063 63.04 0.000
#> .pbc3 3.755 0.063 59.77 0.000
#> .pbc4 3.790 0.061 61.93 0.000
#> .att3 3.723 0.064 58.41 0.000
#> .att2 3.838 0.062 62.19 0.000
#> .att1 4.210 0.060 70.04 0.000
#> .att4 3.689 0.065 56.67 0.000
#> .sn4 4.500 0.051 87.68 0.000
#> .sn2 4.348 0.054 80.00 0.000
#> .sn3 4.388 0.055 80.11 0.000
#> .sn1 4.470 0.052 85.91 0.000
#> .int2 3.722 0.067 55.89 0.000
#> .int1 3.867 0.066 58.78 0.000
#> .int3 3.739 0.066 56.46 0.000
#> .int4 3.783 0.066 57.04 0.000
#> .beh3 3.275 0.071 46.41 0.000
#> .beh2 3.186 0.070 45.49 0.000
#> .beh1 3.041 0.068 44.78 0.000
#> .beh4 3.177 0.068 46.84 0.000
#> .BEH -0.617 0.042 -14.67 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> PBC ~~
#> ATT 3.664 0.177 20.68 0.000
#> SN 1.956 0.116 16.88 0.000
#> ATT ~~
#> SN 1.679 0.107 15.62 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .pbc2 0.672 0.038 17.72 0.000
#> .pbc1 1.480 0.067 22.16 0.000
#> .pbc3 0.769 0.040 19.34 0.000
#> .pbc4 1.477 0.066 22.34 0.000
#> .att3 0.292 0.024 11.98 0.000
#> .att2 0.309 0.024 13.11 0.000
#> .att1 1.286 0.057 22.57 0.000
#> .att4 1.585 0.070 22.68 0.000
#> .sn4 1.365 0.061 22.43 0.000
#> .sn2 0.494 0.034 14.37 0.000
#> .sn3 0.371 0.033 11.36 0.000
#> .sn1 1.449 0.064 22.53 0.000
#> .int2 0.234 0.014 17.08 0.000
#> .int1 0.408 0.020 20.39 0.000
#> .int3 0.331 0.017 19.34 0.000
#> .int4 0.272 0.015 18.17 0.000
#> .beh3 0.439 0.031 14.26 0.000
#> .beh2 0.530 0.033 16.13 0.000
#> .beh1 1.841 0.081 22.70 0.000
#> .beh4 1.913 0.084 22.80 0.000
#> PBC 4.390 0.209 20.99 0.000
#> ATT 4.458 0.197 22.60 0.000
#> SN 1.714 0.116 14.73 0.000
#> .INT 0.508 0.036 14.05 0.000
#> .BEH 0.455 0.032 14.34 0.000
#>
# }