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,
  boot.R    = 50
)
summary(fit_slopes_cont)
#> plssem (0.1.2) 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
#> 
#> Fit Measures:
#>   Chi-Square                                   127.210
#>   Degrees of Freedom                                49
#>   SRMR                                           0.008
#>   RMSEA                                          0.018
#> 
#> 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.542
#>   W                                              0.553
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X =~          
#>     x1              0.927      0.011   88.076    0.000
#>     x2              0.826      0.012   70.155    0.000
#>     x3              0.879      0.008  114.274    0.000
#>   Z =~          
#>     z1              0.916      0.009  101.063    0.000
#>     z2              0.833      0.011   76.484    0.000
#>     z3              0.871      0.010   84.302    0.000
#>   Y =~          
#>     y1              0.915      0.011   81.475    0.000
#>     y2              0.852      0.013   67.315    0.000
#>     y3              0.866      0.016   54.246    0.000
#>   W =~          
#>     w1              0.916      0.012   78.965    0.000
#>     w2              0.834      0.013   62.542    0.000
#>     w3              0.878      0.013   67.093    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   Y ~           
#>     X               0.293      0.023   12.879    0.000
#>     Z               0.444      0.051    8.649    0.000
#>   W ~           
#>     X               0.393      0.038   10.338    0.000
#>     Z               0.248      0.069    3.571    0.000
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .Y               0.010      0.045    0.215    0.830
#>    .W               0.010      0.035    0.286    0.775
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X ~~          
#>     Z               0.175      0.013   13.626    0.000
#>   Y~X ~~        
#>     Y~1            -0.004      0.006   -0.582    0.560
#>   Y~Z ~~        
#>     Y~1            -0.025      0.015   -1.716    0.086
#>     Y~X             0.012      0.009    1.412    0.158
#>   W~X ~~        
#>     W~1             0.003      0.010    0.318    0.751
#>   W~Z ~~        
#>     W~1             0.009      0.012    0.798    0.425
#>     W~X             0.013      0.010    1.314    0.189
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>     X               1.000                             
#>     Z               1.000                             
#>    .Y               0.458      0.066    6.966    0.000
#>    .W               0.447      0.065    6.919    0.000
#>    .x1              0.140      0.019    7.200    0.000
#>    .x2              0.317      0.020   16.250    0.000
#>    .x3              0.228      0.014   16.785    0.000
#>    .z1              0.161      0.017    9.682    0.000
#>    .z2              0.306      0.018   16.821    0.000
#>    .z3              0.241      0.018   13.402    0.000
#>    .y1              0.162      0.020    7.918    0.000
#>    .y2              0.274      0.022   12.726    0.000
#>    .y3              0.250      0.027    9.093    0.000
#>    .w1              0.160      0.021    7.542    0.000
#>    .w2              0.305      0.022   13.780    0.000
#>    .w3              0.229      0.023    9.999    0.000
#>     Y~1             0.086      0.021    4.161    0.000
#>     Y~X             0.018      0.005    3.301    0.001
#>     Y~Z             0.105      0.023    4.576    0.000
#>     W~1             0.059      0.014    4.254    0.000
#>     W~X             0.095      0.014    6.583    0.000
#>     W~Z             0.144      0.030    4.859    0.000

Ordered Indicators

fit_slopes_ord <- pls(
  slopes_model,
  data      = randomSlopesOrdered,
  bootstrap = TRUE,
  boot.R    = 50,
  ordered   = colnames(randomSlopesOrdered) # explicitly specify variables as ordered
)
summary(fit_slopes_ord)
#> plssem (0.1.2) 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
#> 
#> Fit Measures:
#>   Chi-Square                                   263.372
#>   Degrees of Freedom                                49
#>   SRMR                                           0.010
#>   RMSEA                                          0.030
#> 
#> 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.535
#>   W                                              0.547
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X =~          
#>     x1              0.933      0.013   73.200    0.000
#>     x2              0.818      0.012   65.706    0.000
#>     x3              0.888      0.013   70.871    0.000
#>   Z =~          
#>     z1              0.917      0.011   81.489    0.000
#>     z2              0.845      0.013   64.009    0.000
#>     z3              0.871      0.012   74.685    0.000
#>   Y =~          
#>     y1              0.918      0.011   84.890    0.000
#>     y2              0.843      0.013   67.128    0.000
#>     y3              0.869      0.014   60.930    0.000
#>   W =~          
#>     w1              0.914      0.012   78.720    0.000
#>     w2              0.825      0.017   49.767    0.000
#>     w3              0.886      0.014   61.789    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   Y ~           
#>     X               0.290      0.018   16.126    0.000
#>     Z               0.451      0.040   11.261    0.000
#>   W ~           
#>     X               0.391      0.044    8.906    0.000
#>     Z               0.245      0.055    4.429    0.000
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .Y               0.011      0.045    0.247    0.805
#>    .W               0.009      0.029    0.302    0.762
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   X ~~          
#>     Z               0.168      0.013   12.587    0.000
#>   Y~X ~~        
#>     Y~1            -0.006      0.006   -1.000    0.317
#>   Y~Z ~~        
#>     Y~1            -0.024      0.016   -1.532    0.125
#>     Y~X             0.012      0.010    1.231    0.218
#>   W~X ~~        
#>     W~1             0.004      0.008    0.454    0.650
#>   W~Z ~~        
#>     W~1             0.009      0.012    0.761    0.447
#>     W~X             0.016      0.012    1.388    0.165
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>     X               1.000                             
#>     Z               1.000                             
#>    .Y               0.465      0.044   10.475    0.000
#>    .W               0.453      0.058    7.802    0.000
#>    .x1              0.130      0.024    5.476    0.000
#>    .x2              0.331      0.020   16.243    0.000
#>    .x3              0.211      0.022    9.482    0.000
#>    .z1              0.159      0.021    7.688    0.000
#>    .z2              0.286      0.022   12.778    0.000
#>    .z3              0.242      0.020   11.920    0.000
#>    .y1              0.156      0.020    7.896    0.000
#>    .y2              0.289      0.021   13.705    0.000
#>    .y3              0.246      0.025    9.954    0.000
#>    .w1              0.165      0.021    7.817    0.000
#>    .w2              0.319      0.027   11.662    0.000
#>    .w3              0.215      0.025    8.506    0.000
#>     Y~1             0.080      0.022    3.589    0.000
#>     Y~X             0.018      0.004    4.180    0.000
#>     Y~Z             0.102      0.016    6.263    0.000
#>     W~1             0.055      0.011    4.923    0.000
#>     W~X             0.099      0.017    5.742    0.000
#>     W~Z             0.142      0.032    4.493    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,
  boot.R    = 50
)
summary(fit_intercepts_cont)
#> plssem (0.1.2) 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
#> 
#> Fit Measures:
#>   Chi-Square                                    24.372
#>   Degrees of Freedom                                10
#>   SRMR                                           0.003
#>   RMSEA                                          0.012
#> 
#> R-squared (indicators):
#>   y1                                             0.891
#>   y2                                             0.785
#>   y3                                             0.814
#> 
#> R-squared (latents):
#>   f                                              0.744
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f =~          
#>     y1              0.944      0.007  128.789    0.000
#>     y2              0.886      0.011   79.392    0.000
#>     y3              0.902      0.013   69.710    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f ~           
#>     x1              0.238      0.007   35.473    0.000
#>     x2              0.162      0.006   27.333    0.000
#>     x3              0.077      0.005   15.803    0.000
#>     w1              0.128      0.037    3.482    0.000
#>     w2              0.091      0.039    2.333    0.020
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f              -0.013      0.042   -0.302    0.763
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   x1 ~~         
#>     x2              0.104      0.009   11.271    0.000
#>     x3              0.004      0.010    0.418    0.676
#>     w1              0.000                             
#>     w2              0.000                             
#>   x2 ~~         
#>     x3              0.097      0.010    9.588    0.000
#>     w1              0.000                             
#>     w2              0.000                             
#>   x3 ~~         
#>     w1              0.000                             
#>     w2              0.000                             
#>   w1 ~~         
#>     w2             -0.041      0.051   -0.797    0.425
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f               0.256      0.032    7.992    0.000
#>     x1              1.000                             
#>     x2              1.000                             
#>     x3              1.000                             
#>     w1              1.000                             
#>     w2              1.000                             
#>    .y1              0.109      0.014    7.832    0.000
#>    .y2              0.215      0.020   10.778    0.000
#>    .y3              0.186      0.023    8.005    0.000
#>     f~1             0.621      0.032   19.180    0.000

Ordered Indicators

fit_intercepts_ord <- pls(
  intercepts_model,
  data      = randomInterceptsOrdered,
  bootstrap = TRUE,
  boot.R    = 50,
  ordered   = colnames(randomInterceptsOrdered) # explicitly specify variables as ordered
)
summary(fit_intercepts_ord)
#> plssem (0.1.2) 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
#> 
#> Fit Measures:
#>   Chi-Square                                    25.508
#>   Degrees of Freedom                                10
#>   SRMR                                           0.003
#>   RMSEA                                          0.012
#> 
#> R-squared (indicators):
#>   y1                                             0.885
#>   y2                                             0.788
#>   y3                                             0.809
#> 
#> R-squared (latents):
#>   f                                              0.685
#> 
#> Latent Variables:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f =~          
#>     y1              0.941      0.011   84.847    0.000
#>     y2              0.888      0.016   54.385    0.000
#>     y3              0.899      0.012   74.084    0.000
#> 
#> Regressions:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   f ~           
#>     x1              0.234      0.008   30.745    0.000
#>     x2              0.154      0.006   25.141    0.000
#>     x3              0.078      0.006   13.533    0.000
#>     w1              0.118      0.040    2.957    0.003
#>     w2              0.079      0.065    1.211    0.226
#> 
#> Intercepts:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f              -0.011      0.033   -0.351    0.725
#> 
#> Covariances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>   x1 ~~         
#>     x2              0.110      0.013    8.671    0.000
#>     x3              0.012      0.010    1.195    0.232
#>     w1              0.001      0.004    0.201    0.841
#>     w2              0.001      0.003    0.305    0.760
#>   x2 ~~         
#>     x3              0.099      0.010    9.993    0.000
#>     w1             -0.003      0.002   -1.218    0.223
#>     w2             -0.001      0.002   -0.541    0.588
#>   x3 ~~         
#>     w1             -0.003      0.003   -0.922    0.357
#>     w2              0.003      0.003    1.134    0.257
#>   w1 ~~         
#>     w2             -0.025      0.053   -0.463    0.643
#> 
#> Variances:
#>                  Estimate  Std.Error  z.value  P(>|z|)
#>    .f               0.315      0.046    6.891    0.000
#>     x1              1.000                             
#>     x2              1.000                             
#>     x3              1.000                             
#>     w1              1.000                             
#>     w2              1.000                             
#>    .y1              0.115      0.021    5.479    0.000
#>    .y2              0.212      0.029    7.256    0.000
#>    .y3              0.191      0.022    8.793    0.000
#>     f~1             0.569      0.036   15.957    0.000