This vignette shows examples of multilevel random slopes and intercept models, with both continuous and ordinal data.
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)
"
fit_slopes_cont <- pls(
slopes_model,
data = randomSlopes,
bootstrap = TRUE,
boot.R = 50
)
summary(fit_slopes_cont)
#> plssem (0.1.4) ended normally after 66 iterations
#> Estimator MCPLSc-MLM
#> Link LINEAR
#>
#> Number of observations 5000
#> Number of iterations 66
#> Number of latent variables 4
#> Number of observed variables 18
#>
#> Fit Measures:
#> Chi-Square 80.781
#> Degrees of Freedom 49
#> SRMR 0.011
#> RMSEA 0.011
#>
#> R-squared (indicators):
#> x1 0.834
#> x2 0.710
#> x3 0.769
#> z1 0.836
#> z2 0.687
#> z3 0.769
#> y1 0.828
#> y2 0.723
#> y3 0.763
#> w1 0.825
#> w2 0.703
#> w3 0.778
#>
#> R-squared (latents):
#> Y 0.328
#> W 0.253
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.913 0.004 247.777 0.000
#> x2 0.843 0.005 160.942 0.000
#> x3 0.877 0.004 197.800 0.000
#> Z =~
#> z1 0.915 0.004 217.391 0.000
#> z2 0.829 0.006 137.653 0.000
#> z3 0.877 0.005 184.341 0.000
#> Y =~
#> y1 0.910 0.007 127.294 0.000
#> y2 0.850 0.011 77.554 0.000
#> y3 0.874 0.008 106.623 0.000
#> W =~
#> w1 0.908 0.006 139.768 0.000
#> w2 0.838 0.011 78.011 0.000
#> w3 0.882 0.008 107.119 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.292 0.026 11.324 0.000
#> Z 0.444 0.043 10.421 0.000
#> W ~
#> X 0.391 0.045 8.698 0.000
#> Z 0.253 0.045 5.647 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.176 0.014 12.912 0.000
#> Y~X ~~
#> Y~1 -0.004 0.005 -0.695 0.487
#> Y~Z ~~
#> Y~1 -0.027 0.014 -1.867 0.062
#> Y~X 0.011 0.008 1.300 0.194
#> W~X ~~
#> W~1 0.004 0.012 0.372 0.710
#> W~Z ~~
#> W~1 0.008 0.012 0.696 0.486
#> W~X 0.010 0.014 0.692 0.489
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.672 0.050 13.377 0.000
#> .W 0.747 0.056 13.463 0.000
#> .x1 0.166 0.007 24.602 0.000
#> .x2 0.290 0.009 32.804 0.000
#> .x3 0.231 0.008 29.745 0.000
#> .z1 0.164 0.008 21.249 0.000
#> .z2 0.313 0.010 31.397 0.000
#> .z3 0.231 0.008 27.654 0.000
#> .y1 0.172 0.013 13.222 0.000
#> .y2 0.277 0.019 14.847 0.000
#> .y3 0.237 0.014 16.556 0.000
#> .w1 0.175 0.012 14.870 0.000
#> .w2 0.297 0.018 16.506 0.000
#> .w3 0.222 0.015 15.318 0.000
#> Y~1 0.086 0.019 4.499 0.000
#> Y~X 0.018 0.007 2.638 0.008
#> Y~Z 0.105 0.020 5.388 0.000
#> W~1 0.057 0.008 6.750 0.000
#> W~X 0.094 0.015 6.480 0.000
#> W~Z 0.149 0.030 4.986 0.000
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.4) ended normally after 64 iterations
#> Estimator MCOrdPLSc-MLM
#> Link PROBIT
#>
#> Number of observations 5000
#> Number of iterations 64
#> Number of latent variables 4
#> Number of observed variables 18
#>
#> Fit Measures:
#> Chi-Square 74.446
#> Degrees of Freedom 49
#> SRMR 0.010
#> RMSEA 0.010
#>
#> R-squared (indicators):
#> x1 0.841
#> x2 0.715
#> x3 0.773
#> z1 0.843
#> z2 0.704
#> z3 0.773
#> y1 0.837
#> y2 0.709
#> y3 0.768
#> w1 0.817
#> w2 0.699
#> w3 0.787
#>
#> R-squared (latents):
#> Y 0.334
#> W 0.244
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.917 0.004 235.044 0.000
#> x2 0.845 0.006 152.337 0.000
#> x3 0.879 0.006 143.625 0.000
#> Z =~
#> z1 0.918 0.004 241.511 0.000
#> z2 0.839 0.006 131.424 0.000
#> z3 0.879 0.006 151.989 0.000
#> Y =~
#> y1 0.915 0.006 147.249 0.000
#> y2 0.842 0.014 59.018 0.000
#> y3 0.876 0.011 81.270 0.000
#> W =~
#> w1 0.904 0.012 76.896 0.000
#> w2 0.836 0.013 66.298 0.000
#> w3 0.887 0.010 91.753 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.290 0.023 12.643 0.000
#> Z 0.453 0.041 11.006 0.000
#> W ~
#> X 0.393 0.043 9.025 0.000
#> Z 0.241 0.054 4.489 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.166 0.018 9.289 0.000
#> Y~X ~~
#> Y~1 -0.006 0.005 -1.061 0.289
#> Y~Z ~~
#> Y~1 -0.024 0.014 -1.797 0.072
#> Y~X 0.011 0.013 0.827 0.408
#> W~X ~~
#> W~1 0.004 0.011 0.343 0.731
#> W~Z ~~
#> W~1 0.012 0.013 0.888 0.374
#> W~X 0.013 0.014 0.899 0.369
#>
#> Thresholds:
#> Estimate Std.Error z.value P(>|z|)
#> x1|t1 -2.810 0.034 -81.822 0.000
#> x1|t2 -1.999 0.046 -43.677 0.000
#> x1|t3 -0.947 0.018 -51.949 0.000
#> x1|t4 0.139 0.016 8.635 0.000
#> x1|t5 1.082 0.020 53.558 0.000
#> x1|t6 2.161 0.046 47.106 0.000
#> x2|t1 -1.963 0.039 -49.780 0.000
#> x2|t2 -0.969 0.016 -61.728 0.000
#> x2|t3 0.279 0.016 17.387 0.000
#> x2|t4 0.966 0.014 68.703 0.000
#> x2|t5 2.270 0.061 36.910 0.000
#> x2|t6 2.964 0.037 81.026 0.000
#> x3|t1 -2.026 0.046 -44.010 0.000
#> x3|t2 -1.150 0.025 -45.864 0.000
#> x3|t3 -0.166 0.017 -10.051 0.000
#> x3|t4 0.665 0.017 38.440 0.000
#> x3|t5 1.836 0.028 66.204 0.000
#> x3|t6 2.685 0.036 74.550 0.000
#> z1|t1 -2.173 0.036 -59.920 0.000
#> z1|t2 -1.320 0.023 -57.522 0.000
#> z1|t3 -0.209 0.016 -12.804 0.000
#> z1|t4 0.845 0.021 40.820 0.000
#> z1|t5 1.867 0.031 60.459 0.000
#> z1|t6 2.673 0.031 85.687 0.000
#> z2|t1 -2.447 0.045 -54.620 0.000
#> z2|t2 -1.433 0.024 -59.830 0.000
#> z2|t3 -0.287 0.017 -16.781 0.000
#> z2|t4 0.813 0.021 38.155 0.000
#> z2|t5 1.538 0.025 60.561 0.000
#> z2|t6 2.589 0.038 67.559 0.000
#> z3|t1 -2.686 0.043 -63.187 0.000
#> z3|t2 -2.082 0.036 -57.149 0.000
#> z3|t3 -1.167 0.024 -49.319 0.000
#> z3|t4 0.093 0.017 5.376 0.000
#> z3|t5 0.984 0.022 44.456 0.000
#> z3|t6 1.985 0.045 44.350 0.000
#> y1|t1 -2.631 0.082 -32.209 0.000
#> y1|t2 -1.767 0.058 -30.308 0.000
#> y1|t3 -0.657 0.050 -13.124 0.000
#> y1|t4 0.405 0.047 8.648 0.000
#> y1|t5 1.446 0.063 22.978 0.000
#> y1|t6 2.437 0.051 47.747 0.000
#> y2|t1 -2.482 0.051 -49.096 0.000
#> y2|t2 -1.709 0.059 -28.994 0.000
#> y2|t3 -0.551 0.049 -11.310 0.000
#> y2|t4 0.228 0.043 5.311 0.000
#> y2|t5 1.393 0.063 22.169 0.000
#> y2|t6 2.408 0.095 25.392 0.000
#> y3|t1 -1.907 0.050 -37.818 0.000
#> y3|t2 -0.939 0.044 -21.145 0.000
#> y3|t3 -0.092 0.048 -1.934 0.053
#> y3|t4 1.095 0.071 15.421 0.000
#> y3|t5 1.989 0.104 19.119 0.000
#> y3|t6 3.320 0.165 20.127 0.000
#> w1|t1 -2.760 0.108 -25.606 0.000
#> w1|t2 -1.680 0.074 -22.705 0.000
#> w1|t3 -0.768 0.041 -18.506 0.000
#> w1|t4 0.265 0.032 8.200 0.000
#> w1|t5 1.081 0.048 22.547 0.000
#> w1|t6 2.366 0.106 22.318 0.000
#> w2|t1 -2.464 0.072 -34.350 0.000
#> w2|t2 -1.614 0.069 -23.561 0.000
#> w2|t3 -0.614 0.043 -14.257 0.000
#> w2|t4 0.572 0.038 14.966 0.000
#> w2|t5 1.415 0.049 29.012 0.000
#> w2|t6 2.416 0.042 57.225 0.000
#> w3|t1 -2.402 0.101 -23.832 0.000
#> w3|t2 -1.405 0.057 -24.626 0.000
#> w3|t3 -0.714 0.037 -19.380 0.000
#> w3|t4 0.576 0.037 15.741 0.000
#> w3|t5 1.521 0.072 20.977 0.000
#> w3|t6 2.262 0.107 21.118 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.666 0.047 14.135 0.000
#> .W 0.756 0.054 13.980 0.000
#> .x1 0.159 0.007 22.227 0.000
#> .x2 0.285 0.009 30.432 0.000
#> .x3 0.227 0.011 21.064 0.000
#> .z1 0.157 0.007 22.555 0.000
#> .z2 0.296 0.011 27.581 0.000
#> .z3 0.227 0.010 22.365 0.000
#> .y1 0.163 0.011 14.306 0.000
#> .y2 0.291 0.024 12.114 0.000
#> .y3 0.232 0.019 12.282 0.000
#> .w1 0.183 0.021 8.610 0.000
#> .w2 0.301 0.021 14.276 0.000
#> .w3 0.213 0.017 12.408 0.000
#> Y~1 0.086 0.021 4.089 0.000
#> Y~X 0.019 0.008 2.389 0.017
#> Y~Z 0.103 0.016 6.550 0.000
#> W~1 0.059 0.014 4.200 0.000
#> W~X 0.099 0.022 4.573 0.000
#> W~Z 0.150 0.036 4.118 0.000
intercepts_model <- '
f =~ y1 + y2 + y3
f ~ x1 + x2 + x3 + w1 + w2 + (1 | cluster)
'
fit_intercepts_cont <- pls(
intercepts_model,
data = randomIntercepts,
bootstrap = TRUE,
boot.R = 50
)
summary(fit_intercepts_cont)
#> plssem (0.1.4) ended normally after 76 iterations
#> Estimator MCPLSc-MLM
#> Link LINEAR
#>
#> Number of observations 10000
#> Number of iterations 76
#> Number of latent variables 1
#> Number of observed variables 9
#>
#> Fit Measures:
#> Chi-Square 15.539
#> Degrees of Freedom 10
#> SRMR 0.003
#> RMSEA 0.007
#>
#> R-squared (indicators):
#> y1 0.882
#> y2 0.788
#> y3 0.821
#>
#> R-squared (latents):
#> f 0.123
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.939 0.003 269.366 0.000
#> y2 0.888 0.005 171.308 0.000
#> y3 0.906 0.004 212.293 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.237 0.005 46.459 0.000
#> x2 0.161 0.006 28.103 0.000
#> x3 0.077 0.006 12.082 0.000
#> w1 0.128 0.038 3.396 0.001
#> w2 0.092 0.040 2.274 0.023
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.105 0.011 9.460 0.000
#> x3 0.005 0.009 0.508 0.612
#> w1 0.001 0.000 16889.735 0.000
#> w2 0.000 0.000 -0.159 0.874
#> x2 ~~
#> x3 0.096 0.011 8.687 0.000
#> w1 0.000 0.000 -6.385 0.000
#> w2 0.000 0.000 -1.511 0.131
#> x3 ~~
#> w1 0.001 0.000 14.112 0.000
#> w2 0.001 0.000 7.593 0.000
#> w1 ~~
#> w2 -0.041 0.046 -0.890 0.374
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.877 0.011 77.047 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.118 0.007 18.060 0.000
#> .y2 0.212 0.009 23.046 0.000
#> .y3 0.179 0.008 23.130 0.000
#> f~1 0.618 0.036 17.069 0.000
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.4) ended normally after 59 iterations
#> Estimator MCOrdPLSc-MLM
#> Link PROBIT
#>
#> Number of observations 10000
#> Number of iterations 59
#> Number of latent variables 1
#> Number of observed variables 9
#>
#> Fit Measures:
#> Chi-Square 11.538
#> Degrees of Freedom 10
#> SRMR 0.004
#> RMSEA 0.004
#>
#> R-squared (indicators):
#> y1 0.877
#> y2 0.786
#> y3 0.819
#>
#> R-squared (latents):
#> f 0.126
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.936 0.005 205.450 0.000
#> y2 0.887 0.011 82.557 0.000
#> y3 0.905 0.006 155.902 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.251 0.007 35.318 0.000
#> x2 0.159 0.008 19.400 0.000
#> x3 0.080 0.007 11.563 0.000
#> w1 0.122 0.035 3.438 0.001
#> w2 0.077 0.043 1.784 0.074
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.110 0.012 8.957 0.000
#> x3 0.011 0.012 0.874 0.382
#> w1 0.006 0.003 1.639 0.101
#> w2 0.000 0.005 0.061 0.951
#> x2 ~~
#> x3 0.100 0.012 8.065 0.000
#> w1 -0.001 0.004 -0.261 0.794
#> w2 -0.002 0.010 -0.174 0.862
#> x3 ~~
#> w1 -0.001 0.005 -0.263 0.792
#> w2 0.005 0.005 0.928 0.354
#> w1 ~~
#> w2 -0.027 0.062 -0.433 0.665
#>
#> Thresholds:
#> Estimate Std.Error z.value P(>|z|)
#> y1|t1 -2.652 0.067 -39.460 0.000
#> y1|t2 -1.815 0.054 -33.365 0.000
#> y1|t3 -0.421 0.040 -10.646 0.000
#> y1|t4 0.337 0.042 8.072 0.000
#> y1|t5 1.319 0.054 24.428 0.000
#> y1|t6 2.347 0.041 57.318 0.000
#> y2|t1 -2.917 0.051 -57.540 0.000
#> y2|t2 -1.938 0.055 -35.196 0.000
#> y2|t3 -0.976 0.042 -23.050 0.000
#> y2|t4 0.188 0.037 5.065 0.000
#> y2|t5 1.034 0.038 27.052 0.000
#> y2|t6 2.228 0.110 20.298 0.000
#> y3|t1 -2.285 0.115 -19.895 0.000
#> y3|t2 -1.265 0.046 -27.336 0.000
#> y3|t3 0.010 0.039 0.264 0.792
#> y3|t4 0.698 0.039 17.981 0.000
#> y3|t5 1.764 0.073 24.029 0.000
#> y3|t6 2.775 0.073 37.968 0.000
#> x1|t1 -2.372 0.022 -109.813 0.000
#> x1|t2 -1.361 0.014 -96.526 0.000
#> x1|t3 -0.670 0.010 -68.508 0.000
#> x1|t4 0.502 0.009 57.839 0.000
#> x1|t5 1.506 0.017 88.366 0.000
#> x1|t6 2.551 0.025 101.573 0.000
#> x2|t1 -2.887 0.029 -97.864 0.000
#> x2|t2 -1.991 0.025 -80.237 0.000
#> x2|t3 -1.000 0.012 -80.050 0.000
#> x2|t4 -0.116 0.008 -14.989 0.000
#> x2|t5 0.804 0.011 72.446 0.000
#> x2|t6 1.940 0.025 76.847 0.000
#> x3|t1 -2.845 0.029 -96.448 0.000
#> x3|t2 -1.966 0.027 -73.961 0.000
#> x3|t3 -0.845 0.011 -75.077 0.000
#> x3|t4 -0.146 0.008 -17.709 0.000
#> x3|t5 1.010 0.012 86.397 0.000
#> x3|t6 2.202 0.040 54.722 0.000
#> w1|t1 -2.814 0.139 -20.279 0.000
#> w1|t2 -2.006 0.121 -16.640 0.000
#> w1|t3 -0.956 0.074 -12.947 0.000
#> w1|t4 0.105 0.068 1.535 0.125
#> w1|t5 1.258 0.087 14.539 0.000
#> w1|t6 2.581 0.102 25.275 0.000
#> w2|t1 -1.993 0.137 -14.588 0.000
#> w2|t2 -0.960 0.074 -13.054 0.000
#> w2|t3 -0.126 0.062 -2.025 0.043
#> w2|t4 0.740 0.078 9.539 0.000
#> w2|t5 1.817 0.154 11.828 0.000
#> w2|t6 2.501 0.188 13.339 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.874 0.011 77.498 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.123 0.009 14.462 0.000
#> .y2 0.214 0.019 11.206 0.000
#> .y3 0.181 0.011 17.209 0.000
#> f~1 0.665 0.040 16.643 0.000