This vignette shows examples of multilevel random slopes and intercept models, with both continuous and ordinal data.

Random Slopes Model

slopes_model <- "
  X =~ x1 + x2 + x3
  Z =~ z1 + z2 + z3
  Y =~ y1 + y2 + y3
  W =~ w1 + w2 + w3
  Y ~ X + Z + (1 + X + Z | cluster)
  W ~ X + Z + (1 + X + Z | cluster)
"

Continuous Indicators

fit_slopes_cont <- pls(
  slopes_model,
  data      = randomSlopes,
  bootstrap = TRUE,
  sample    = 500
)
summary(fit_slopes_cont)
#> plssem (0.1.0) ended normally after 3 iterations
#> 
#>   Estimator                                   PLSc-MLM
#>   Link                                          LINEAR
#>                                                       
#>   Number of observations                          5000
#>   Number of iterations                               3
#>   Number of latent variables                         4
#>   Number of observed variables                      18
#> 
#> R-squared (indicators):
#>   x1                                             0.860
#>   x2                                             0.683
#>   x3                                             0.772
#>   z1                                             0.839
#>   z2                                             0.694
#>   z3                                             0.759
#>   y1                                             0.838
#>   y2                                             0.726
#>   y3                                             0.750
#>   w1                                             0.840
#>   w2                                             0.695
#>   w3                                             0.771
#> 
#> R-squared (latents):
#>   Y                                              0.463
#>   W                                              0.466
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X =~          
#>     x1              0.927      0.010   94.499    0.000
#>     x2              0.826      0.010   79.596    0.000
#>     x3              0.879      0.008  109.713    0.000
#>   Z =~          
#>     z1              0.916      0.009   97.804    0.000
#>     z2              0.833      0.011   73.352    0.000
#>     z3              0.871      0.010   90.910    0.000
#>   Y =~          
#>     y1              0.915      0.010   88.329    0.000
#>     y2              0.852      0.013   66.676    0.000
#>     y3              0.866      0.013   68.517    0.000
#>   W =~          
#>     w1              0.916      0.011   86.735    0.000
#>     w2              0.834      0.015   54.481    0.000
#>     w3              0.878      0.013   68.238    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   Y ~           
#>     X               0.293      0.021   13.938    0.000
#>     Z               0.444      0.037   11.871    0.000
#>   W ~           
#>     X               0.393      0.034   11.665    0.000
#>     Z               0.248      0.054    4.590    0.000
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .Y               0.009      0.005    1.918    0.055
#>    .W               0.009      0.008    1.229    0.219
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X ~~          
#>     Z               0.175      0.013   13.166    0.000
#>   Y~X ~~        
#>     Y~1            -0.003      0.005   -0.643    0.521
#>   Y~Z ~~        
#>     Y~1            -0.024      0.014   -1.724    0.085
#>     Y~X             0.012      0.009    1.433    0.152
#>   W~X ~~        
#>     W~1             0.003      0.011    0.272    0.785
#>   W~Z ~~        
#>     W~1             0.009      0.012    0.757    0.449
#>     W~X             0.013      0.011    1.188    0.235
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>     X               1.000                             
#>     Z               1.000                             
#>    .Y               0.537      0.027   19.574    0.000
#>    .W               0.534      0.031   17.253    0.000
#>    .x1              0.140      0.018    7.691    0.000
#>    .x2              0.317      0.017   18.480    0.000
#>    .x3              0.228      0.014   16.161    0.000
#>    .z1              0.161      0.017    9.366    0.000
#>    .z2              0.306      0.019   16.177    0.000
#>    .z3              0.241      0.017   14.467    0.000
#>    .y1              0.162      0.019    8.570    0.000
#>    .y2              0.274      0.022   12.618    0.000
#>    .y3              0.250      0.022   11.456    0.000
#>    .w1              0.160      0.019    8.278    0.000
#>    .w2              0.305      0.025   12.010    0.000
#>    .w3              0.229      0.023   10.168    0.000
#>     Y~1             0.079      0.020    3.958    0.000
#>     Y~X             0.018      0.005    3.455    0.001
#>     Y~Z             0.105      0.016    6.707    0.000
#>     W~1             0.054      0.012    4.459    0.000
#>     W~X             0.095      0.016    6.063    0.000
#>     W~Z             0.144      0.029    5.061    0.000

Ordered Indicators

fit_slopes_ord <- pls(
  slopes_model,
  data      = randomSlopesOrdered,
  bootstrap = TRUE,
  sample    = 500,
  ordered   = colnames(randomSlopesOrdered) # explicitly specify variables as ordered
)
summary(fit_slopes_ord)
#> plssem (0.1.0) ended normally after 3 iterations
#> 
#>   Estimator                                OrdPLSc-MLM
#>   Link                                          PROBIT
#>                                                       
#>   Number of observations                          5000
#>   Number of iterations                               3
#>   Number of latent variables                         4
#>   Number of observed variables                      18
#> 
#> R-squared (indicators):
#>   x1                                             0.870
#>   x2                                             0.669
#>   x3                                             0.789
#>   z1                                             0.841
#>   z2                                             0.714
#>   z3                                             0.758
#>   y1                                             0.844
#>   y2                                             0.711
#>   y3                                             0.754
#>   w1                                             0.835
#>   w2                                             0.681
#>   w3                                             0.785
#> 
#> R-squared (latents):
#>   Y                                              0.440
#>   W                                              0.440
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X =~          
#>     x1              0.933      0.012   74.871    0.000
#>     x2              0.818      0.011   76.372    0.000
#>     x3              0.888      0.012   76.871    0.000
#>   Z =~          
#>     z1              0.917      0.012   75.773    0.000
#>     z2              0.845      0.012   68.564    0.000
#>     z3              0.871      0.011   77.803    0.000
#>   Y =~          
#>     y1              0.918      0.011   84.880    0.000
#>     y2              0.843      0.014   61.946    0.000
#>     y3              0.869      0.015   58.771    0.000
#>   W =~          
#>     w1              0.914      0.012   77.640    0.000
#>     w2              0.825      0.017   49.815    0.000
#>     w3              0.886      0.015   57.553    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   Y ~           
#>     X               0.290      0.022   13.336    0.000
#>     Z               0.451      0.037   12.047    0.000
#>   W ~           
#>     X               0.391      0.037   10.613    0.000
#>     Z               0.245      0.051    4.764    0.000
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .Y               0.011      0.005    2.160    0.031
#>    .W               0.009      0.008    1.098    0.272
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X ~~          
#>     Z               0.168      0.014   12.194    0.000
#>   Y~X ~~        
#>     Y~1            -0.006      0.006   -1.146    0.252
#>   Y~Z ~~        
#>     Y~1            -0.024      0.014   -1.664    0.096
#>     Y~X             0.012      0.009    1.424    0.154
#>   W~X ~~        
#>     W~1             0.004      0.011    0.331    0.741
#>   W~Z ~~        
#>     W~1             0.009      0.012    0.762    0.446
#>     W~X             0.016      0.012    1.342    0.180
#> 
#> Thresholds:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>     x1|t1          -2.848      0.100  -28.353    0.000
#>     x1|t2          -1.999      0.035  -56.466    0.000
#>     x1|t3          -0.947      0.019  -50.909    0.000
#>     x1|t4           0.134      0.018    7.466    0.000
#>     x1|t5           1.088      0.023   47.028    0.000
#>     x1|t6           2.165      0.043   50.665    0.000
#>     x2|t1          -1.940      0.035  -55.569    0.000
#>     x2|t2          -0.976      0.019  -50.853    0.000
#>     x2|t3           0.276      0.018   15.006    0.000
#>     x2|t4           0.974      0.018   53.687    0.000
#>     x2|t5           2.245      0.050   44.710    0.000
#>     x2|t6           2.989      0.250   11.961    0.000
#>     x3|t1          -2.018      0.058  -34.543    0.000
#>     x3|t2          -1.143      0.049  -23.391    0.000
#>     x3|t3          -0.178      0.042   -4.259    0.000
#>     x3|t4           0.671      0.057   11.727    0.000
#>     x3|t5           1.852      0.055   33.473    0.000
#>     x3|t6           2.727      0.235   11.616    0.000
#>     z1|t1          -2.149      0.051  -41.973    0.000
#>     z1|t2          -1.324      0.057  -23.292    0.000
#>     z1|t3          -0.218      0.051   -4.310    0.000
#>     z1|t4           0.844      0.051   16.699    0.000
#>     z1|t5           1.878      0.048   39.203    0.000
#>     z1|t6           2.636      0.239   11.007    0.000
#>     z2|t1          -2.468      0.082  -30.058    0.000
#>     z2|t2          -1.433      0.058  -24.718    0.000
#>     z2|t3          -0.286      0.053   -5.357    0.000
#>     z2|t4           0.810      0.037   21.693    0.000
#>     z2|t5           1.524      0.053   28.642    0.000
#>     z2|t6           2.620      0.246   10.664    0.000
#>     z3|t1          -2.706      0.092  -29.411    0.000
#>     z3|t2          -2.084      0.054  -38.578    0.000
#>     z3|t3          -1.158      0.061  -18.906    0.000
#>     z3|t4           0.093      0.043    2.136    0.033
#>     z3|t5           0.980      0.051   19.193    0.000
#>     z3|t6           1.981      0.210    9.426    0.000
#>     y1|t1          -2.524      0.104  -24.273    0.000
#>     y1|t2          -1.758      0.082  -21.330    0.000
#>     y1|t3          -0.678      0.068   -9.902    0.000
#>     y1|t4           0.405      0.066    6.137    0.000
#>     y1|t5           1.464      0.069   21.274    0.000
#>     y1|t6           2.382      0.240    9.913    0.000
#>     y2|t1          -2.447      0.102  -24.024    0.000
#>     y2|t2          -1.691      0.077  -21.990    0.000
#>     y2|t3          -0.576      0.058   -9.903    0.000
#>     y2|t4           0.232      0.069    3.372    0.001
#>     y2|t5           1.410      0.068   20.692    0.000
#>     y2|t6           2.349      0.212   11.075    0.000
#>     y3|t1          -1.884      0.080  -23.478    0.000
#>     y3|t2          -0.960      0.062  -15.399    0.000
#>     y3|t3          -0.104      0.073   -1.430    0.153
#>     y3|t4           1.128      0.066   17.085    0.000
#>     y3|t5           1.981      0.233    8.487    0.000
#>     y3|t6           3.090      0.773    3.999    0.000
#>     w1|t1          -2.636      0.182  -14.497    0.000
#>     w1|t2          -1.679      0.151  -11.141    0.000
#>     w1|t3          -0.798      0.161   -4.942    0.000
#>     w1|t4           0.285      0.137    2.079    0.038
#>     w1|t5           1.104      0.222    4.972    0.000
#>     w1|t6           2.264      0.621    3.643    0.000
#>     w2|t1          -2.428      0.147  -16.468    0.000
#>     w2|t2          -1.649      0.169   -9.732    0.000
#>     w2|t3          -0.621      0.178   -3.486    0.000
#>     w2|t4           0.580      0.136    4.257    0.000
#>     w2|t5           1.427      0.217    6.566    0.000
#>     w2|t6           2.366      0.623    3.798    0.000
#>     w3|t1          -2.357      0.168  -13.996    0.000
#>     w3|t2          -1.433      0.135  -10.592    0.000
#>     w3|t3          -0.732      0.196   -3.739    0.000
#>     w3|t4           0.598      0.140    4.270    0.000
#>     w3|t5           1.525      0.114   13.366    0.000
#>     w3|t6           2.203      0.188   11.697    0.000
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>     X               1.000                             
#>     Z               1.000                             
#>    .Y               0.560      0.026   21.908    0.000
#>    .W               0.560      0.030   18.468    0.000
#>    .x1              0.130      0.023    5.609    0.000
#>    .x2              0.331      0.018   18.856    0.000
#>    .x3              0.211      0.021   10.300    0.000
#>    .z1              0.159      0.022    7.127    0.000
#>    .z2              0.286      0.021   13.742    0.000
#>    .z3              0.242      0.019   12.445    0.000
#>    .y1              0.156      0.020    7.869    0.000
#>    .y2              0.289      0.023   12.643    0.000
#>    .y3              0.246      0.026    9.595    0.000
#>    .w1              0.165      0.021    7.689    0.000
#>    .w2              0.319      0.027   11.718    0.000
#>    .w3              0.215      0.027    7.924    0.000
#>     Y~1             0.076      0.020    3.896    0.000
#>     Y~X             0.018      0.005    3.400    0.001
#>     Y~Z             0.101      0.014    7.023    0.000
#>     W~1             0.052      0.012    4.365    0.000
#>     W~X             0.099      0.015    6.444    0.000
#>     W~Z             0.142      0.028    5.004    0.000

Random Intercepts Model

intercepts_model <- '
  f =~ y1 + y2 + y3
  f ~ x1 + x2 + x3 + w1 + w2 + (1 | cluster)
'

Continuous Indicators

fit_intercepts_cont <- pls(
  intercepts_model,
  data      = randomIntercepts,
  bootstrap = TRUE,
  sample    = 500
)
summary(fit_intercepts_cont)
#> plssem (0.1.0) ended normally after 2 iterations
#> 
#>   Estimator                                   PLSc-MLM
#>   Link                                          LINEAR
#>                                                       
#>   Number of observations                         10000
#>   Number of iterations                               2
#>   Number of latent variables                         1
#>   Number of observed variables                       9
#> 
#> R-squared (indicators):
#>   y1                                             0.891
#>   y2                                             0.785
#>   y3                                             0.814
#> 
#> R-squared (latents):
#>   f                                              0.689
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f =~          
#>     y1              0.944      0.008  112.051    0.000
#>     y2              0.886      0.010   86.471    0.000
#>     y3              0.902      0.009   96.137    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f ~           
#>     x1              0.238      0.008   31.070    0.000
#>     x2              0.162      0.007   23.984    0.000
#>     x3              0.077      0.006   12.950    0.000
#>     w1              0.128      0.040    3.240    0.001
#>     w2              0.091      0.039    2.319    0.020
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f              -0.012      0.008   -1.571    0.116
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   x1 ~~         
#>     x2              0.104      0.010   10.156    0.000
#>     x3              0.004      0.011    0.399    0.690
#>     w1              0.000                             
#>     w2              0.000                             
#>   x2 ~~         
#>     x3              0.097      0.011    9.147    0.000
#>     w1              0.000                             
#>     w2              0.000                             
#>   x3 ~~         
#>     w1              0.000                             
#>     w2              0.000                             
#>   w1 ~~         
#>     w2             -0.041      0.048   -0.849    0.396
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f               0.311      0.013   23.587    0.000
#>     x1              1.000                             
#>     x2              1.000                             
#>     x3              1.000                             
#>     w1              1.000                             
#>     w2              1.000                             
#>    .y1              0.109      0.016    6.819    0.000
#>    .y2              0.215      0.018   11.810    0.000
#>    .y3              0.186      0.017   11.025    0.000
#>     f~1             0.582      0.021   27.351    0.000

Ordered Indicators

fit_intercepts_ord <- pls(
  intercepts_model,
  data      = randomInterceptsOrdered,
  bootstrap = TRUE,
  sample    = 500,
  ordered   = colnames(randomInterceptsOrdered) # explicitly specify variables as ordered
)
summary(fit_intercepts_ord)
#> plssem (0.1.0) ended normally after 2 iterations
#> 
#>   Estimator                                OrdPLSc-MLM
#>   Link                                          PROBIT
#>                                                       
#>   Number of observations                         10000
#>   Number of iterations                               2
#>   Number of latent variables                         1
#>   Number of observed variables                       9
#> 
#> R-squared (indicators):
#>   y1                                             0.885
#>   y2                                             0.788
#>   y3                                             0.809
#> 
#> R-squared (latents):
#>   f                                              0.656
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f =~          
#>     y1              0.941      0.012   80.402    0.000
#>     y2              0.888      0.013   67.410    0.000
#>     y3              0.899      0.013   69.779    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f ~           
#>     x1              0.241      0.009   27.697    0.000
#>     x2              0.158      0.008   20.657    0.000
#>     x3              0.080      0.007   11.887    0.000
#>     w1              0.121      0.041    2.936    0.003
#>     w2              0.081      0.044    1.843    0.065
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f              -0.011      0.008   -1.458    0.145
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   x1 ~~         
#>     x2              0.110      0.011   10.217    0.000
#>     x3              0.012      0.012    0.973    0.331
#>     w1              0.001      0.003    0.219    0.827
#>     w2              0.001      0.003    0.306    0.759
#>   x2 ~~         
#>     x3              0.099      0.011    8.877    0.000
#>     w1             -0.003      0.003   -1.054    0.292
#>     w2             -0.001      0.003   -0.447    0.655
#>   x3 ~~         
#>     w1             -0.003      0.003   -0.967    0.333
#>     w2              0.003      0.003    1.064    0.287
#>   w1 ~~         
#>     w2             -0.025      0.057   -0.433    0.665
#> 
#> Thresholds:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>     y1|t1          -2.620      0.097  -27.039    0.000
#>     y1|t2          -1.777      0.053  -33.538    0.000
#>     y1|t3          -0.423      0.042  -10.067    0.000
#>     y1|t4           0.323      0.040    8.045    0.000
#>     y1|t5           1.326      0.048   27.708    0.000
#>     y1|t6           2.362      0.083   28.397    0.000
#>     y2|t1          -2.878      0.105  -27.337    0.000
#>     y2|t2          -1.902      0.056  -33.980    0.000
#>     y2|t3          -0.976      0.043  -22.673    0.000
#>     y2|t4           0.179      0.037    4.820    0.000
#>     y2|t5           1.039      0.041   25.159    0.000
#>     y2|t6           2.251      0.072   31.454    0.000
#>     y3|t1          -2.254      0.074  -30.280    0.000
#>     y3|t2          -1.257      0.047  -26.550    0.000
#>     y3|t3           0.005      0.039    0.128    0.898
#>     y3|t4           0.693      0.041   16.962    0.000
#>     y3|t5           1.797      0.061   29.257    0.000
#>     y3|t6           2.807      0.138   20.296    0.000
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f               0.344      0.015   23.468    0.000
#>     x1              1.000                             
#>     x2              1.000                             
#>     x3              1.000                             
#>     w1              1.000                             
#>     w2              1.000                             
#>    .y1              0.115      0.022    5.206    0.000
#>    .y2              0.212      0.023    9.059    0.000
#>    .y3              0.191      0.023    8.246    0.000
#>     f~1             0.562      0.021   26.364    0.000