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 79.145
#> Degrees of Freedom 49
#> SRMR 0.010
#> 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 249.952 0.000
#> x2 0.843 0.005 157.292 0.000
#> x3 0.877 0.004 206.404 0.000
#> Z =~
#> z1 0.915 0.005 173.983 0.000
#> z2 0.829 0.006 142.480 0.000
#> z3 0.877 0.004 208.635 0.000
#> Y =~
#> y1 0.910 0.006 144.662 0.000
#> y2 0.850 0.011 77.605 0.000
#> y3 0.874 0.008 105.514 0.000
#> W =~
#> w1 0.908 0.007 124.362 0.000
#> w2 0.838 0.010 79.836 0.000
#> w3 0.882 0.007 118.747 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.292 0.022 12.968 0.000
#> Z 0.444 0.046 9.744 0.000
#> W ~
#> X 0.391 0.043 9.158 0.000
#> Z 0.253 0.054 4.725 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.176 0.012 14.724 0.000
#> Y~X ~~
#> Y~1 -0.004 0.006 -0.634 0.526
#> Y~Z ~~
#> Y~1 -0.027 0.017 -1.597 0.110
#> Y~X 0.011 0.007 1.428 0.153
#> W~X ~~
#> W~1 0.004 0.013 0.342 0.733
#> W~Z ~~
#> W~1 0.008 0.016 0.510 0.610
#> W~X 0.010 0.012 0.805 0.421
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.672 0.046 14.557 0.000
#> .W 0.747 0.054 13.784 0.000
#> .x1 0.166 0.007 24.818 0.000
#> .x2 0.290 0.009 32.060 0.000
#> .x3 0.231 0.007 31.039 0.000
#> .z1 0.164 0.010 17.006 0.000
#> .z2 0.313 0.010 32.498 0.000
#> .z3 0.231 0.007 31.298 0.000
#> .y1 0.172 0.011 15.025 0.000
#> .y2 0.277 0.019 14.857 0.000
#> .y3 0.237 0.014 16.384 0.000
#> .w1 0.175 0.013 13.231 0.000
#> .w2 0.297 0.018 16.892 0.000
#> .w3 0.222 0.013 16.980 0.000
#> Y~1 0.086 0.025 3.411 0.001
#> Y~X 0.018 0.004 3.982 0.000
#> Y~Z 0.105 0.017 6.290 0.000
#> W~1 0.057 0.015 3.758 0.000
#> W~X 0.094 0.013 7.290 0.000
#> W~Z 0.149 0.025 5.879 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 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 76.597
#> Degrees of Freedom 49
#> SRMR 0.012
#> RMSEA 0.011
#>
#> R-squared (indicators):
#> x1 0.839
#> x2 0.714
#> x3 0.772
#> z1 0.843
#> z2 0.706
#> z3 0.772
#> y1 0.838
#> y2 0.710
#> y3 0.767
#> w1 0.818
#> w2 0.699
#> w3 0.787
#>
#> R-squared (latents):
#> Y 0.333
#> W 0.248
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.916 0.005 173.922 0.000
#> x2 0.845 0.005 157.808 0.000
#> x3 0.879 0.006 158.957 0.000
#> Z =~
#> z1 0.918 0.006 146.193 0.000
#> z2 0.840 0.007 122.916 0.000
#> z3 0.879 0.006 137.493 0.000
#> Y =~
#> y1 0.915 0.009 99.385 0.000
#> y2 0.843 0.016 51.750 0.000
#> y3 0.876 0.007 127.964 0.000
#> W =~
#> w1 0.904 0.008 107.670 0.000
#> w2 0.836 0.017 48.920 0.000
#> w3 0.887 0.007 129.469 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.291 0.025 11.731 0.000
#> Z 0.450 0.040 11.286 0.000
#> W ~
#> X 0.387 0.047 8.320 0.000
#> Z 0.251 0.047 5.378 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.169 0.013 12.887 0.000
#> Y~X ~~
#> Y~1 -0.007 0.007 -1.017 0.309
#> Y~Z ~~
#> Y~1 -0.025 0.014 -1.776 0.076
#> Y~X 0.010 0.009 1.172 0.241
#> W~X ~~
#> W~1 0.004 0.011 0.361 0.718
#> W~Z ~~
#> W~1 0.009 0.016 0.550 0.582
#> W~X 0.016 0.017 0.899 0.369
#>
#> Thresholds:
#> Estimate Std.Error z.value P(>|z|)
#> x1|t1 -2.820 0.041 -68.971 0.000
#> x1|t2 -2.005 0.039 -51.325 0.000
#> x1|t3 -0.950 0.017 -54.881 0.000
#> x1|t4 0.129 0.018 6.982 0.000
#> x1|t5 1.086 0.029 37.184 0.000
#> x1|t6 2.133 0.042 50.685 0.000
#> x2|t1 -1.956 0.036 -54.744 0.000
#> x2|t2 -0.979 0.017 -59.279 0.000
#> x2|t3 0.281 0.019 15.039 0.000
#> x2|t4 0.969 0.023 42.298 0.000
#> x2|t5 2.247 0.068 33.139 0.000
#> x2|t6 3.035 0.030 102.657 0.000
#> x3|t1 -2.073 0.051 -40.303 0.000
#> x3|t2 -1.129 0.022 -50.313 0.000
#> x3|t3 -0.175 0.019 -9.409 0.000
#> x3|t4 0.670 0.019 35.636 0.000
#> x3|t5 1.836 0.043 42.989 0.000
#> x3|t6 2.764 0.039 70.640 0.000
#> z1|t1 -2.137 0.038 -56.271 0.000
#> z1|t2 -1.326 0.027 -49.663 0.000
#> z1|t3 -0.212 0.019 -11.404 0.000
#> z1|t4 0.842 0.017 49.549 0.000
#> z1|t5 1.874 0.034 54.495 0.000
#> z1|t6 2.667 0.042 63.707 0.000
#> z2|t1 -2.468 0.047 -52.477 0.000
#> z2|t2 -1.438 0.030 -47.602 0.000
#> z2|t3 -0.292 0.014 -21.582 0.000
#> z2|t4 0.804 0.021 37.708 0.000
#> z2|t5 1.524 0.026 59.042 0.000
#> z2|t6 2.650 0.031 84.742 0.000
#> z3|t1 -2.725 0.042 -64.141 0.000
#> z3|t2 -2.090 0.045 -46.177 0.000
#> z3|t3 -1.158 0.027 -42.813 0.000
#> z3|t4 0.086 0.017 5.061 0.000
#> z3|t5 0.982 0.018 54.445 0.000
#> z3|t6 1.954 0.045 43.667 0.000
#> y1|t1 -2.699 0.058 -46.737 0.000
#> y1|t2 -1.776 0.073 -24.479 0.000
#> y1|t3 -0.650 0.055 -11.761 0.000
#> y1|t4 0.405 0.045 8.993 0.000
#> y1|t5 1.429 0.056 25.401 0.000
#> y1|t6 2.415 0.074 32.780 0.000
#> y2|t1 -2.537 0.068 -37.125 0.000
#> y2|t2 -1.707 0.064 -26.677 0.000
#> y2|t3 -0.561 0.047 -11.926 0.000
#> y2|t4 0.229 0.035 6.466 0.000
#> y2|t5 1.385 0.056 24.744 0.000
#> y2|t6 2.372 0.083 28.662 0.000
#> y3|t1 -1.907 0.055 -34.826 0.000
#> y3|t2 -0.931 0.057 -16.215 0.000
#> y3|t3 -0.097 0.046 -2.109 0.035
#> y3|t4 1.108 0.041 27.226 0.000
#> y3|t5 1.971 0.086 22.990 0.000
#> y3|t6 3.102 0.101 30.723 0.000
#> w1|t1 -2.790 0.073 -38.253 0.000
#> w1|t2 -1.645 0.070 -23.505 0.000
#> w1|t3 -0.775 0.048 -16.104 0.000
#> w1|t4 0.264 0.045 5.890 0.000
#> w1|t5 1.073 0.049 21.883 0.000
#> w1|t6 2.348 0.147 15.969 0.000
#> w2|t1 -2.490 0.082 -30.245 0.000
#> w2|t2 -1.624 0.077 -21.211 0.000
#> w2|t3 -0.605 0.049 -12.275 0.000
#> w2|t4 0.554 0.048 11.608 0.000
#> w2|t5 1.416 0.068 20.684 0.000
#> w2|t6 2.475 0.068 36.319 0.000
#> w3|t1 -2.417 0.076 -31.899 0.000
#> w3|t2 -1.395 0.066 -21.122 0.000
#> w3|t3 -0.718 0.047 -15.253 0.000
#> w3|t4 0.566 0.041 13.875 0.000
#> w3|t5 1.509 0.058 26.118 0.000
#> w3|t6 2.312 0.102 22.572 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.667 0.047 14.276 0.000
#> .W 0.752 0.053 14.075 0.000
#> .x1 0.161 0.010 16.697 0.000
#> .x2 0.286 0.009 31.575 0.000
#> .x3 0.228 0.010 23.460 0.000
#> .z1 0.157 0.012 13.652 0.000
#> .z2 0.294 0.011 25.636 0.000
#> .z3 0.228 0.011 20.298 0.000
#> .y1 0.162 0.017 9.613 0.000
#> .y2 0.290 0.027 10.552 0.000
#> .y3 0.233 0.012 19.393 0.000
#> .w1 0.182 0.015 11.984 0.000
#> .w2 0.301 0.029 10.538 0.000
#> .w3 0.213 0.012 17.546 0.000
#> Y~1 0.085 0.024 3.556 0.000
#> Y~X 0.018 0.005 3.855 0.000
#> Y~Z 0.104 0.014 7.236 0.000
#> W~1 0.059 0.014 4.124 0.000
#> W~X 0.102 0.019 5.285 0.000
#> W~Z 0.151 0.039 3.878 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 62 iterations
#> Estimator MCPLSc-MLM
#> Link LINEAR
#>
#> Number of observations 10000
#> Number of iterations 62
#> Number of latent variables 1
#> Number of observed variables 9
#>
#> Fit Measures:
#> Chi-Square 15.042
#> Degrees of Freedom 10
#> SRMR 0.003
#> RMSEA 0.007
#>
#> R-squared (indicators):
#> y1 0.881
#> y2 0.788
#> y3 0.822
#>
#> R-squared (latents):
#> f 0.123
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.939 0.003 337.982 0.000
#> y2 0.888 0.005 175.503 0.000
#> y3 0.907 0.004 203.450 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.239 0.005 43.848 0.000
#> x2 0.162 0.006 26.995 0.000
#> x3 0.077 0.006 13.882 0.000
#> w1 0.129 0.031 4.149 0.000
#> w2 0.091 0.044 2.087 0.037
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.103 0.011 9.598 0.000
#> x3 -0.002 0.011 -0.168 0.866
#> w1 0.000 0.000 313.265 0.000
#> w2 0.001 0.000 8.935 0.000
#> x2 ~~
#> x3 0.097 0.010 9.288 0.000
#> w1 -0.001 0.000 -213.457 0.000
#> w2 -0.001 0.001 -1.218 0.223
#> x3 ~~
#> w1 -0.002 0.000 -14.049 0.000
#> w2 0.001 0.000 5.265 0.000
#> w1 ~~
#> w2 -0.042 0.051 -0.820 0.412
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.877 0.010 90.964 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.119 0.005 22.832 0.000
#> .y2 0.212 0.009 23.617 0.000
#> .y3 0.178 0.008 22.037 0.000
#> f~1 0.617 0.039 15.782 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) did NOT END NORMALLY after 67 iterations
#> Estimator MCOrdPLSc-MLM
#> Link PROBIT
#>
#> Number of observations 10000
#> Number of iterations 67
#> Number of latent variables 1
#> Number of observed variables 9
#>
#> Fit Measures:
#> Chi-Square 10.570
#> Degrees of Freedom 10
#> SRMR 0.004
#> RMSEA 0.002
#>
#> R-squared (indicators):
#> y1 0.877
#> y2 0.787
#> y3 0.820
#>
#> R-squared (latents):
#> f 0.123
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.937 0.005 181.746 0.000
#> y2 0.887 0.009 102.557 0.000
#> y3 0.906 0.005 199.350 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.240 0.007 33.324 0.000
#> x2 0.158 0.008 20.047 0.000
#> x3 0.080 0.007 12.169 0.000
#> w1 0.123 0.041 2.994 0.003
#> w2 0.078 0.044 1.781 0.075
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.111 0.012 9.094 0.000
#> x3 0.010 0.013 0.746 0.456
#> w1 0.001 0.004 0.289 0.773
#> w2 0.002 0.008 0.307 0.759
#> x2 ~~
#> x3 0.098 0.011 9.125 0.000
#> w1 -0.004 0.004 -1.070 0.285
#> w2 0.000 0.004 -0.075 0.940
#> x3 ~~
#> w1 -0.004 0.003 -1.250 0.211
#> w2 0.003 0.005 0.627 0.531
#> w1 ~~
#> w2 -0.027 0.056 -0.476 0.634
#>
#> Thresholds:
#> Estimate Std.Error z.value P(>|z|)
#> y1|t1 -2.548 0.048 -53.085 0.000
#> y1|t2 -1.775 0.061 -28.976 0.000
#> y1|t3 -0.426 0.041 -10.350 0.000
#> y1|t4 0.322 0.049 6.616 0.000
#> y1|t5 1.325 0.057 23.315 0.000
#> y1|t6 2.359 0.052 45.090 0.000
#> y2|t1 -2.766 0.053 -52.552 0.000
#> y2|t2 -1.899 0.055 -34.717 0.000
#> y2|t3 -0.987 0.046 -21.394 0.000
#> y2|t4 0.184 0.053 3.452 0.001
#> y2|t5 1.045 0.045 23.094 0.000
#> y2|t6 2.251 0.094 23.846 0.000
#> y3|t1 -2.236 0.090 -24.903 0.000
#> y3|t2 -1.273 0.050 -25.300 0.000
#> y3|t3 0.002 0.045 0.038 0.970
#> y3|t4 0.697 0.049 14.240 0.000
#> y3|t5 1.785 0.069 25.942 0.000
#> y3|t6 2.743 0.119 23.025 0.000
#> x1|t1 -2.335 0.018 -127.321 0.000
#> x1|t2 -1.348 0.013 -101.197 0.000
#> x1|t3 -0.673 0.008 -85.675 0.000
#> x1|t4 0.491 0.009 57.448 0.000
#> x1|t5 1.519 0.017 89.517 0.000
#> x1|t6 2.586 0.027 95.000 0.000
#> x2|t1 -2.806 0.027 -104.651 0.000
#> x2|t2 -2.001 0.026 -76.382 0.000
#> x2|t3 -1.019 0.011 -91.938 0.000
#> x2|t4 -0.114 0.009 -12.594 0.000
#> x2|t5 0.809 0.010 84.730 0.000
#> x2|t6 1.944 0.025 77.787 0.000
#> x3|t1 -2.993 0.030 -99.713 0.000
#> x3|t2 -1.919 0.022 -86.721 0.000
#> x3|t3 -0.850 0.009 -89.548 0.000
#> x3|t4 -0.149 0.006 -23.903 0.000
#> x3|t5 1.001 0.009 107.509 0.000
#> x3|t6 2.254 0.041 54.531 0.000
#> w1|t1 -2.779 0.170 -16.387 0.000
#> w1|t2 -1.995 0.138 -14.437 0.000
#> w1|t3 -0.968 0.076 -12.732 0.000
#> w1|t4 0.110 0.051 2.148 0.032
#> w1|t5 1.258 0.079 15.839 0.000
#> w1|t6 2.563 0.141 18.194 0.000
#> w2|t1 -1.970 0.133 -14.775 0.000
#> w2|t2 -0.951 0.069 -13.728 0.000
#> w2|t3 -0.119 0.071 -1.683 0.092
#> w2|t4 0.736 0.064 11.580 0.000
#> w2|t5 1.798 0.132 13.675 0.000
#> w2|t6 2.509 0.138 18.150 0.000
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.877 0.011 78.355 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.123 0.010 12.732 0.000
#> .y2 0.213 0.015 13.894 0.000
#> .y3 0.180 0.008 21.811 0.000
#> f~1 0.621 0.028 21.988 0.000