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,
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.533
#> W 0.547
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.927 0.010 93.951 0.000
#> x2 0.826 0.011 75.478 0.000
#> x3 0.879 0.008 110.066 0.000
#> Z =~
#> z1 0.916 0.010 93.533 0.000
#> z2 0.833 0.011 72.645 0.000
#> z3 0.871 0.010 88.915 0.000
#> Y =~
#> y1 0.915 0.010 94.014 0.000
#> y2 0.852 0.013 66.928 0.000
#> y3 0.866 0.013 66.743 0.000
#> W =~
#> w1 0.916 0.011 87.166 0.000
#> w2 0.834 0.015 57.024 0.000
#> w3 0.878 0.013 65.966 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.293 0.021 14.222 0.000
#> Z 0.444 0.036 12.288 0.000
#> W ~
#> X 0.393 0.033 11.959 0.000
#> Z 0.248 0.048 5.177 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .Y 0.009 0.004 2.076 0.038
#> .W 0.009 0.008 1.261 0.207
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.175 0.013 13.833 0.000
#> Y~X ~~
#> Y~1 -0.003 0.005 -0.664 0.507
#> Y~Z ~~
#> Y~1 -0.024 0.013 -1.870 0.062
#> Y~X 0.012 0.009 1.412 0.158
#> W~X ~~
#> W~1 0.003 0.011 0.273 0.785
#> W~Z ~~
#> W~1 0.009 0.012 0.744 0.457
#> W~X 0.013 0.012 1.136 0.256
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.467 0.030 15.627 0.000
#> .W 0.453 0.030 15.008 0.000
#> .x1 0.140 0.018 7.647 0.000
#> .x2 0.317 0.018 17.536 0.000
#> .x3 0.228 0.014 16.207 0.000
#> .z1 0.161 0.018 8.976 0.000
#> .z2 0.306 0.019 15.991 0.000
#> .z3 0.241 0.017 14.128 0.000
#> .y1 0.162 0.018 9.128 0.000
#> .y2 0.274 0.022 12.677 0.000
#> .y3 0.250 0.022 11.157 0.000
#> .w1 0.160 0.019 8.340 0.000
#> .w2 0.305 0.024 12.546 0.000
#> .w3 0.229 0.023 9.821 0.000
#> Y~1 0.079 0.018 4.272 0.000
#> Y~X 0.018 0.005 3.386 0.001
#> Y~Z 0.105 0.015 6.838 0.000
#> W~1 0.054 0.012 4.583 0.000
#> W~X 0.095 0.015 6.473 0.000
#> W~Z 0.144 0.027 5.335 0.000
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.531
#> W 0.544
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> X =~
#> x1 0.933 0.014 67.322 0.000
#> x2 0.818 0.012 68.337 0.000
#> x3 0.888 0.012 74.864 0.000
#> Z =~
#> z1 0.917 0.012 75.528 0.000
#> z2 0.845 0.013 67.108 0.000
#> z3 0.871 0.012 73.803 0.000
#> Y =~
#> y1 0.918 0.012 79.101 0.000
#> y2 0.843 0.014 61.415 0.000
#> y3 0.869 0.015 58.951 0.000
#> W =~
#> w1 0.914 0.011 80.637 0.000
#> w2 0.825 0.016 51.329 0.000
#> w3 0.886 0.015 58.599 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.290 0.021 13.518 0.000
#> Z 0.451 0.037 12.171 0.000
#> W ~
#> X 0.391 0.034 11.399 0.000
#> Z 0.245 0.050 4.934 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .Y 0.011 0.005 2.176 0.030
#> .W 0.009 0.008 1.132 0.258
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.168 0.014 12.010 0.000
#> Y~X ~~
#> Y~1 -0.006 0.005 -1.187 0.235
#> Y~Z ~~
#> Y~1 -0.024 0.013 -1.756 0.079
#> Y~X 0.012 0.009 1.349 0.177
#> W~X ~~
#> W~1 0.004 0.011 0.330 0.741
#> W~Z ~~
#> W~1 0.009 0.012 0.752 0.452
#> W~X 0.016 0.012 1.380 0.168
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.469 0.030 15.789 0.000
#> .W 0.456 0.031 14.831 0.000
#> .x1 0.130 0.026 5.051 0.000
#> .x2 0.331 0.020 16.879 0.000
#> .x3 0.211 0.021 10.019 0.000
#> .z1 0.159 0.022 7.111 0.000
#> .z2 0.286 0.021 13.426 0.000
#> .z3 0.242 0.021 11.801 0.000
#> .y1 0.156 0.021 7.341 0.000
#> .y2 0.289 0.023 12.531 0.000
#> .y3 0.246 0.026 9.618 0.000
#> .w1 0.165 0.021 7.991 0.000
#> .w2 0.319 0.026 12.040 0.000
#> .w3 0.215 0.027 8.084 0.000
#> Y~1 0.076 0.019 4.018 0.000
#> Y~X 0.018 0.005 3.384 0.001
#> Y~Z 0.101 0.015 6.806 0.000
#> W~1 0.052 0.012 4.240 0.000
#> W~X 0.099 0.015 6.483 0.000
#> W~Z 0.142 0.027 5.212 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,
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.705
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.944 0.008 116.717 0.000
#> y2 0.886 0.010 86.329 0.000
#> y3 0.902 0.009 97.375 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.238 0.008 31.146 0.000
#> x2 0.162 0.007 24.139 0.000
#> x3 0.077 0.006 12.270 0.000
#> w1 0.128 0.039 3.261 0.001
#> w2 0.091 0.039 2.357 0.018
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .f -0.012 0.008 -1.516 0.130
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.104 0.010 10.015 0.000
#> x3 0.004 0.010 0.415 0.678
#> w1 0.000
#> w2 0.000
#> x2 ~~
#> x3 0.097 0.011 8.482 0.000
#> w1 0.000
#> w2 0.000
#> x3 ~~
#> w1 0.000
#> w2 0.000
#> w1 ~~
#> w2 -0.041 0.050 -0.809 0.419
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.295 0.015 19.398 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.109 0.015 7.110 0.000
#> .y2 0.215 0.018 11.801 0.000
#> .y3 0.186 0.017 11.163 0.000
#> f~1 0.582 0.021 27.421 0.000
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.684
#>
#> Latent Variables:
#> Estimate Std.Error z.value P(>|z|)
#> f =~
#> y1 0.941 0.011 84.207 0.000
#> y2 0.888 0.013 67.588 0.000
#> y3 0.899 0.012 72.114 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.241 0.008 28.482 0.000
#> x2 0.158 0.008 20.590 0.000
#> x3 0.080 0.006 12.365 0.000
#> w1 0.121 0.042 2.861 0.004
#> w2 0.081 0.044 1.852 0.064
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .f -0.011 0.008 -1.499 0.134
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.110 0.011 10.025 0.000
#> x3 0.012 0.011 1.084 0.278
#> w1 0.001 0.004 0.208 0.835
#> w2 0.001 0.003 0.325 0.745
#> x2 ~~
#> x3 0.099 0.011 8.963 0.000
#> w1 -0.003 0.003 -1.014 0.310
#> w2 -0.001 0.003 -0.479 0.632
#> x3 ~~
#> w1 -0.003 0.003 -1.042 0.298
#> w2 0.003 0.003 1.072 0.284
#> w1 ~~
#> w2 -0.025 0.055 -0.449 0.654
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.316 0.016 19.364 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.115 0.021 5.456 0.000
#> .y2 0.212 0.023 9.080 0.000
#> .y3 0.191 0.022 8.535 0.000
#> f~1 0.562 0.021 26.651 0.000