Skip to contents

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!

Usage

twostep(model.syntax, data, method = "lms", ...)

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 and modsem_da)

Value

modsem object with class modsem_pi or modsem_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.13, 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 (1.0.13) 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.859    0.000
#>     Z               0.570      0.026   22.209    0.000
#>     X:Z             0.719      0.026   27.192    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.876    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.834    0.000
#> 

est_qml <- twostep(m1, oneInt, method = "qml")
summary(est_qml)
#> 
#> modsem (1.0.13) ended normally after 7 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.869    0.000
#>     Z               0.570      0.026   22.216    0.000
#>     X:Z             0.720      0.026   27.200    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.873    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.811    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.13, 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 (1.0.13) ended normally after 26 iterations
#> 
#>   Estimator                                        LMS
#>   Optimization method                       EMA-NLMINB
#>   Number of model parameters                         9
#>                                                       
#>   Number of observations                          1169
#>  
#> Loglikelihood and Information Criteria:
#>   Loglikelihood                              -35376.39
#>   Akaike (AIC)                                70770.78
#>   Bayesian (BIC)                              70816.36
#>  
#> Numerical Integration:
#>   Points of integration (per dim)                   32
#>   Dimensions                                         1
#>   Total points of integration                       32
#>  
#> Fit Measures for Baseline Model (H0):
#>                                               Standard
#>   Chi-square                                   5520.02
#>   Degrees of Freedom (Chi-square)                  222
#>   P-value (Chi-square)                           0.000
#>   RMSEA                                          0.143
#>                                                       
#>   Loglikelihood                              -35523.38
#>   Akaike (AIC)                                71062.75
#>   Bayesian (BIC)                              71103.26
#>  
#> Comparative Fit to H0 (LRT test):
#>   Loglikelihood change                          146.98
#>   Difference test (D)                           293.97
#>   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|)
#>   ATT =~        
#>     att3            1.000                             
#>     att2            0.964      0.011   84.974    0.000
#>     att1            0.812      0.017   47.128    0.000
#>     att4            0.869      0.019   45.694    0.000
#>   SN =~         
#>     sn4             1.000                             
#>     sn2             1.314      0.039   33.493    0.000
#>     sn3             1.352      0.040   34.142    0.000
#>     sn1             1.000      0.039   25.867    0.000
#>   PBC =~        
#>     pbc2            1.000                             
#>     pbc1            0.853      0.020   42.452    0.000
#>     pbc3            0.936      0.017   55.716    0.000
#>     pbc4            0.813      0.020   40.990    0.000
#>   INT =~        
#>     int2            1.000                             
#>     int1            0.970      0.011   92.005    0.000
#>     int3            0.984      0.010   98.963    0.000
#>     int4            0.992      0.009  104.919    0.000
#>   BEH =~        
#>     beh3            1.000                             
#>     beh2            0.983      0.013   76.139    0.000
#>     beh1            0.812      0.019   43.185    0.000
#>     beh4            0.802      0.019   42.038    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   INT ~         
#>     ATT            -0.047      0.025   -1.864    0.062
#>     SN              0.047      0.031    1.511    0.131
#>     PBC             1.024      0.030   34.678    0.000
#>   BEH ~         
#>     PBC             0.387      0.049    7.869    0.000
#>     INT             0.603      0.046   13.184    0.000
#>     INT:PBC         0.140      0.008   18.058    0.000
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .pbc2            4.019      0.066   61.072    0.000
#>    .pbc1            3.986      0.063   63.043    0.000
#>    .pbc3            3.755      0.063   59.773    0.000
#>    .pbc4            3.790      0.061   61.927    0.000
#>    .att3            3.723      0.064   58.406    0.000
#>    .att2            3.838      0.062   62.185    0.000
#>    .att1            4.210      0.060   70.042    0.000
#>    .att4            3.689      0.065   56.670    0.000
#>    .sn4             4.500      0.051   87.680    0.000
#>    .sn2             4.348      0.054   79.997    0.000
#>    .sn3             4.388      0.055   80.107    0.000
#>    .sn1             4.470      0.052   85.908    0.000
#>    .int2            3.722      0.067   55.889    0.000
#>    .int1            3.867      0.066   58.777    0.000
#>    .int3            3.739      0.066   56.460    0.000
#>    .int4            3.783      0.066   57.036    0.000
#>    .beh3            3.275      0.071   46.415    0.000
#>    .beh2            3.186      0.070   45.493    0.000
#>    .beh1            3.041      0.068   44.782    0.000
#>    .beh4            3.177      0.068   46.843    0.000
#>    .BEH            -0.617      0.042  -14.669    0.000
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   ATT ~~        
#>     SN              1.679      0.107   15.622    0.000
#>   PBC ~~        
#>     ATT             3.664      0.177   20.682    0.000
#>     SN              1.956      0.116   16.882    0.000
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .pbc2            0.672      0.038   17.721    0.000
#>    .pbc1            1.480      0.067   22.161    0.000
#>    .pbc3            0.769      0.040   19.338    0.000
#>    .pbc4            1.477      0.066   22.345    0.000
#>    .att3            0.292      0.024   11.979    0.000
#>    .att2            0.309      0.024   13.111    0.000
#>    .att1            1.286      0.057   22.565    0.000
#>    .att4            1.585      0.070   22.679    0.000
#>    .sn4             1.365      0.061   22.430    0.000
#>    .sn2             0.494      0.034   14.369    0.000
#>    .sn3             0.371      0.033   11.362    0.000
#>    .sn1             1.449      0.064   22.533    0.000
#>    .int2            0.234      0.014   17.084    0.000
#>    .int1            0.408      0.020   20.388    0.000
#>    .int3            0.331      0.017   19.338    0.000
#>    .int4            0.272      0.015   18.173    0.000
#>    .beh3            0.439      0.031   14.256    0.000
#>    .beh2            0.530      0.033   16.128    0.000
#>    .beh1            1.841      0.081   22.704    0.000
#>    .beh4            1.913      0.084   22.795    0.000
#>     ATT             4.458      0.197   22.602    0.000
#>     SN              1.714      0.116   14.726    0.000
#>     PBC             4.390      0.209   20.993    0.000
#>    .INT             0.507      0.036   14.061    0.000
#>    .BEH             0.456      0.032   14.335    0.000
#> 
# }