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.3) ended normally after 67 iterations
#> Estimator MCPLSc-MLM
#> Link LINEAR
#>
#> Number of observations 5000
#> Number of iterations 67
#> Number of latent variables 4
#> Number of observed variables 18
#>
#> Fit Measures:
#> Chi-Square 133.887
#> Degrees of Freedom 49
#> SRMR 0.010
#> RMSEA 0.019
#>
#> R-squared (indicators):
#> x1 0.859
#> x2 0.685
#> x3 0.770
#> z1 0.838
#> z2 0.697
#> z3 0.757
#> y1 0.839
#> y2 0.729
#> y3 0.747
#> w1 0.839
#> w2 0.696
#> w3 0.771
#>
#> R-squared (latents):
#> Y 0.328
#> W 0.250
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.927 0.010 95.119 0.000
#> x2 0.828 0.012 68.661 0.000
#> x3 0.878 0.006 139.499 0.000
#> Z =~
#> z1 0.916 0.010 88.233 0.000
#> z2 0.835 0.011 72.853 0.000
#> z3 0.870 0.008 106.541 0.000
#> Y =~
#> y1 0.916 0.010 90.555 0.000
#> y2 0.854 0.013 67.025 0.000
#> y3 0.864 0.013 68.827 0.000
#> W =~
#> w1 0.916 0.012 74.464 0.000
#> w2 0.834 0.017 49.474 0.000
#> w3 0.878 0.012 76.184 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.292 0.022 13.004 0.000
#> Z 0.444 0.045 9.753 0.000
#> W ~
#> X 0.392 0.043 9.164 0.000
#> Z 0.250 0.054 4.647 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.176 0.012 14.658 0.000
#> Y~X ~~
#> Y~1 -0.004 0.006 -0.638 0.523
#> Y~Z ~~
#> Y~1 -0.027 0.017 -1.614 0.107
#> Y~X 0.011 0.007 1.430 0.153
#> W~X ~~
#> W~1 0.004 0.013 0.333 0.739
#> W~Z ~~
#> W~1 0.008 0.016 0.508 0.611
#> W~X 0.010 0.012 0.801 0.423
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.672 0.046 14.553 0.000
#> .W 0.750 0.054 13.909 0.000
#> .x1 0.141 0.018 7.775 0.000
#> .x2 0.315 0.020 15.775 0.000
#> .x3 0.230 0.011 20.800 0.000
#> .z1 0.162 0.019 8.503 0.000
#> .z2 0.303 0.019 15.857 0.000
#> .z3 0.243 0.014 17.100 0.000
#> .y1 0.161 0.019 8.704 0.000
#> .y2 0.271 0.022 12.487 0.000
#> .y3 0.253 0.022 11.674 0.000
#> .w1 0.161 0.023 7.137 0.000
#> .w2 0.304 0.028 10.827 0.000
#> .w3 0.229 0.020 11.337 0.000
#> Y~1 0.086 0.025 3.422 0.001
#> Y~X 0.018 0.004 4.006 0.000
#> Y~Z 0.106 0.017 6.348 0.000
#> W~1 0.057 0.015 3.746 0.000
#> W~X 0.094 0.013 7.201 0.000
#> W~Z 0.148 0.025 6.009 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.3) ended normally after 53 iterations
#> Estimator MCOrdPLSc-MLM
#> Link PROBIT
#>
#> Number of observations 5000
#> Number of iterations 53
#> Number of latent variables 4
#> Number of observed variables 18
#>
#> Fit Measures:
#> Chi-Square 150.260
#> Degrees of Freedom 49
#> SRMR 0.013
#> RMSEA 0.020
#>
#> R-squared (indicators):
#> x1 0.869
#> x2 0.670
#> x3 0.787
#> z1 0.843
#> z2 0.717
#> z3 0.757
#> y1 0.848
#> y2 0.712
#> y3 0.755
#> w1 0.840
#> w2 0.683
#> w3 0.785
#>
#> R-squared (latents):
#> Y 0.326
#> W 0.244
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.932 0.015 61.472 0.000
#> x2 0.819 0.014 57.913 0.000
#> x3 0.887 0.014 63.660 0.000
#> Z =~
#> z1 0.918 0.015 61.648 0.000
#> z2 0.847 0.014 62.425 0.000
#> z3 0.870 0.012 71.070 0.000
#> Y =~
#> y1 0.921 0.014 64.955 0.000
#> y2 0.844 0.010 87.855 0.000
#> y3 0.869 0.015 58.767 0.000
#> W =~
#> w1 0.917 0.019 48.548 0.000
#> w2 0.826 0.016 52.469 0.000
#> w3 0.886 0.012 72.398 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.285 0.022 13.146 0.000
#> Z 0.450 0.041 11.079 0.000
#> W ~
#> X 0.387 0.049 7.948 0.000
#> Z 0.250 0.052 4.841 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.164 0.017 9.906 0.000
#> Y~X ~~
#> Y~1 -0.007 0.006 -1.165 0.244
#> Y~Z ~~
#> Y~1 -0.025 0.019 -1.339 0.181
#> Y~X 0.010 0.010 1.042 0.297
#> W~X ~~
#> W~1 0.004 0.010 0.397 0.691
#> W~Z ~~
#> W~1 0.009 0.015 0.590 0.555
#> W~X 0.016 0.011 1.423 0.155
#>
#> Thresholds:
#> Estimate Std.Error z.value P(>|z|)
#> x1|t1 -2.892 0.047 -61.131 0.000
#> x1|t2 -1.999 0.038 -52.529 0.000
#> x1|t3 -0.946 0.019 -48.929 0.000
#> x1|t4 0.134 0.017 7.974 0.000
#> x1|t5 1.076 0.024 45.460 0.000
#> x1|t6 2.168 0.054 40.108 0.000
#> x2|t1 -1.968 0.038 -52.379 0.000
#> x2|t2 -0.971 0.019 -52.354 0.000
#> x2|t3 0.274 0.016 17.409 0.000
#> x2|t4 0.975 0.018 55.607 0.000
#> x2|t5 2.235 0.069 32.476 0.000
#> x2|t6 2.951 0.037 80.842 0.000
#> x3|t1 -2.037 0.046 -44.334 0.000
#> x3|t2 -1.143 0.030 -38.048 0.000
#> x3|t3 -0.178 0.018 -9.988 0.000
#> x3|t4 0.669 0.015 43.264 0.000
#> x3|t5 1.853 0.037 49.752 0.000
#> x3|t6 2.737 0.049 55.405 0.000
#> z1|t1 -2.150 0.051 -41.964 0.000
#> z1|t2 -1.325 0.033 -40.081 0.000
#> z1|t3 -0.216 0.020 -10.798 0.000
#> z1|t4 0.844 0.021 40.204 0.000
#> z1|t5 1.893 0.037 51.606 0.000
#> z1|t6 2.613 0.044 59.957 0.000
#> z2|t1 -2.458 0.048 -51.202 0.000
#> z2|t2 -1.446 0.033 -43.964 0.000
#> z2|t3 -0.288 0.018 -15.598 0.000
#> z2|t4 0.811 0.016 50.822 0.000
#> z2|t5 1.532 0.027 56.053 0.000
#> z2|t6 2.606 0.037 71.329 0.000
#> z3|t1 -2.685 0.052 -51.692 0.000
#> z3|t2 -2.096 0.051 -41.071 0.000
#> z3|t3 -1.162 0.029 -39.723 0.000
#> z3|t4 0.090 0.013 6.902 0.000
#> z3|t5 0.975 0.019 51.954 0.000
#> z3|t6 1.964 0.052 37.533 0.000
#> y1|t1 -2.658 0.053 -50.402 0.000
#> y1|t2 -1.792 0.095 -18.824 0.000
#> y1|t3 -0.649 0.058 -11.207 0.000
#> y1|t4 0.395 0.050 7.966 0.000
#> y1|t5 1.433 0.060 24.014 0.000
#> y1|t6 2.391 0.058 41.199 0.000
#> y2|t1 -2.581 0.072 -35.860 0.000
#> y2|t2 -1.702 0.068 -25.073 0.000
#> y2|t3 -0.553 0.051 -10.952 0.000
#> y2|t4 0.230 0.043 5.380 0.000
#> y2|t5 1.400 0.046 30.198 0.000
#> y2|t6 2.337 0.074 31.474 0.000
#> y3|t1 -1.910 0.068 -28.127 0.000
#> y3|t2 -0.942 0.057 -16.470 0.000
#> y3|t3 -0.092 0.043 -2.153 0.031
#> y3|t4 1.104 0.047 23.395 0.000
#> y3|t5 1.951 0.069 28.197 0.000
#> y3|t6 3.178 0.088 35.999 0.000
#> w1|t1 -2.671 0.066 -40.379 0.000
#> w1|t2 -1.655 0.068 -24.268 0.000
#> w1|t3 -0.779 0.036 -21.528 0.000
#> w1|t4 0.269 0.033 8.094 0.000
#> w1|t5 1.091 0.066 16.590 0.000
#> w1|t6 2.355 0.147 15.976 0.000
#> w2|t1 -2.410 0.043 -55.447 0.000
#> w2|t2 -1.630 0.057 -28.657 0.000
#> w2|t3 -0.616 0.037 -16.826 0.000
#> w2|t4 0.561 0.040 14.019 0.000
#> w2|t5 1.411 0.075 18.814 0.000
#> w2|t6 2.500 0.078 32.139 0.000
#> w3|t1 -2.382 0.137 -17.360 0.000
#> w3|t2 -1.415 0.069 -20.643 0.000
#> w3|t3 -0.714 0.038 -18.675 0.000
#> w3|t4 0.583 0.052 11.112 0.000
#> w3|t5 1.519 0.092 16.591 0.000
#> w3|t6 2.270 0.091 24.909 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.674 0.043 15.837 0.000
#> .W 0.756 0.053 14.242 0.000
#> .x1 0.131 0.028 4.639 0.000
#> .x2 0.330 0.023 14.248 0.000
#> .x3 0.213 0.025 8.625 0.000
#> .z1 0.157 0.027 5.754 0.000
#> .z2 0.283 0.023 12.301 0.000
#> .z3 0.243 0.021 11.390 0.000
#> .y1 0.152 0.026 5.832 0.000
#> .y2 0.288 0.016 17.742 0.000
#> .y3 0.245 0.026 9.528 0.000
#> .w1 0.160 0.035 4.615 0.000
#> .w2 0.317 0.026 12.188 0.000
#> .w3 0.215 0.022 9.942 0.000
#> Y~1 0.087 0.025 3.519 0.000
#> Y~X 0.018 0.005 3.440 0.001
#> Y~Z 0.104 0.018 5.674 0.000
#> W~1 0.059 0.015 3.899 0.000
#> W~X 0.103 0.017 6.072 0.000
#> W~Z 0.150 0.027 5.592 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.3) ended normally after 69 iterations
#> Estimator MCPLSc-MLM
#> Link LINEAR
#>
#> Number of observations 10000
#> Number of iterations 69
#> Number of latent variables 1
#> Number of observed variables 9
#>
#> Fit Measures:
#> Chi-Square 26.600
#> Degrees of Freedom 10
#> SRMR 0.003
#> RMSEA 0.013
#>
#> R-squared (indicators):
#> y1 0.892
#> y2 0.783
#> y3 0.815
#>
#> R-squared (latents):
#> f 0.123
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.944 0.008 122.799 0.000
#> y2 0.885 0.009 94.268 0.000
#> y3 0.903 0.009 101.833 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.237 0.005 46.837 0.000
#> x2 0.162 0.006 28.765 0.000
#> x3 0.077 0.007 11.808 0.000
#> w1 0.129 0.039 3.347 0.001
#> w2 0.092 0.032 2.904 0.004
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.103 0.011 9.261 0.000
#> x3 0.005 0.012 0.432 0.666
#> w1 0.001 0.000 1379.363 0.000
#> w2 0.000 0.000 -5.605 0.000
#> x2 ~~
#> x3 0.096 0.013 7.410 0.000
#> w1 0.000 0.000 -114.529 0.000
#> w2 -0.002 0.000 -3.902 0.000
#> x3 ~~
#> w1 0.001 0.000 3.710 0.000
#> w2 -0.001 0.000 -3.360 0.001
#> w1 ~~
#> w2 -0.041 0.039 -1.047 0.295
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.877 0.012 75.386 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.108 0.015 7.464 0.000
#> .y2 0.217 0.017 13.030 0.000
#> .y3 0.185 0.016 11.566 0.000
#> f~1 0.645 0.038 17.104 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.3) ended normally after 69 iterations
#> Estimator MCOrdPLSc-MLM
#> Link PROBIT
#>
#> Number of observations 10000
#> Number of iterations 69
#> Number of latent variables 1
#> Number of observed variables 9
#>
#> Fit Measures:
#> Chi-Square 14.042
#> Degrees of Freedom 10
#> SRMR 0.003
#> RMSEA 0.006
#>
#> R-squared (indicators):
#> y1 0.884
#> y2 0.786
#> y3 0.810
#>
#> R-squared (latents):
#> f 0.121
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.940 0.019 50.751 0.000
#> y2 0.887 0.018 48.459 0.000
#> y3 0.900 0.012 76.701 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.241 0.009 27.169 0.000
#> x2 0.159 0.009 18.299 0.000
#> x3 0.081 0.007 12.251 0.000
#> w1 0.123 0.048 2.549 0.011
#> w2 0.077 0.043 1.800 0.072
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.108 0.010 10.527 0.000
#> x3 0.011 0.010 1.076 0.282
#> w1 0.002 0.004 0.475 0.635
#> w2 0.000 0.008 0.033 0.974
#> x2 ~~
#> x3 0.098 0.010 9.910 0.000
#> w1 -0.002 0.005 -0.373 0.709
#> w2 0.000 0.005 -0.062 0.950
#> x3 ~~
#> w1 -0.003 0.003 -0.852 0.394
#> w2 0.005 0.007 0.754 0.451
#> w1 ~~
#> w2 -0.024 0.069 -0.354 0.723
#>
#> Thresholds:
#> Estimate Std.Error z.value P(>|z|)
#> y1|t1 -2.694 0.049 -54.715 0.000
#> y1|t2 -1.823 0.073 -25.023 0.000
#> y1|t3 -0.408 0.046 -8.899 0.000
#> y1|t4 0.328 0.039 8.351 0.000
#> y1|t5 1.316 0.047 28.014 0.000
#> y1|t6 2.303 0.064 36.051 0.000
#> y2|t1 -2.939 0.043 -68.821 0.000
#> y2|t2 -1.947 0.070 -27.932 0.000
#> y2|t3 -0.974 0.049 -19.839 0.000
#> y2|t4 0.186 0.038 4.908 0.000
#> y2|t5 1.036 0.044 23.556 0.000
#> y2|t6 2.188 0.100 21.960 0.000
#> y3|t1 -2.299 0.085 -26.939 0.000
#> y3|t2 -1.256 0.049 -25.872 0.000
#> y3|t3 0.013 0.046 0.277 0.782
#> y3|t4 0.693 0.041 16.984 0.000
#> y3|t5 1.786 0.063 28.135 0.000
#> y3|t6 2.721 0.087 31.272 0.000
#> x1|t1 -2.446 0.023 -105.772 0.000
#> x1|t2 -1.334 0.013 -99.085 0.000
#> x1|t3 -0.670 0.010 -69.508 0.000
#> x1|t4 0.501 0.008 65.072 0.000
#> x1|t5 1.504 0.018 83.155 0.000
#> x1|t6 2.601 0.023 114.188 0.000
#> x2|t1 -2.927 0.027 -107.895 0.000
#> x2|t2 -2.011 0.031 -63.938 0.000
#> x2|t3 -1.011 0.010 -100.738 0.000
#> x2|t4 -0.109 0.007 -16.039 0.000
#> x2|t5 0.815 0.011 77.513 0.000
#> x2|t6 1.887 0.031 61.297 0.000
#> x3|t1 -2.906 0.029 -101.444 0.000
#> x3|t2 -1.938 0.025 -77.148 0.000
#> x3|t3 -0.842 0.011 -76.361 0.000
#> x3|t4 -0.158 0.008 -20.692 0.000
#> x3|t5 1.008 0.012 86.732 0.000
#> x3|t6 2.203 0.045 48.648 0.000
#> w1|t1 -2.689 0.129 -20.793 0.000
#> w1|t2 -2.021 0.110 -18.404 0.000
#> w1|t3 -0.967 0.063 -15.433 0.000
#> w1|t4 0.110 0.065 1.688 0.091
#> w1|t5 1.257 0.101 12.492 0.000
#> w1|t6 2.552 0.153 16.698 0.000
#> w2|t1 -1.982 0.121 -16.435 0.000
#> w2|t2 -0.939 0.064 -14.773 0.000
#> w2|t3 -0.126 0.066 -1.926 0.054
#> w2|t4 0.738 0.061 12.024 0.000
#> w2|t5 1.827 0.160 11.447 0.000
#> w2|t6 2.508 0.165 15.227 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.879 0.015 59.349 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.116 0.035 3.328 0.001
#> .y2 0.214 0.032 6.596 0.000
#> .y3 0.190 0.021 9.002 0.000
#> f~1 0.612 0.028 22.244 0.000