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.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.009 98.579 0.000
#> x2 0.826 0.012 70.255 0.000
#> x3 0.879 0.007 128.185 0.000
#> Z =~
#> z1 0.916 0.010 88.526 0.000
#> z2 0.833 0.013 65.224 0.000
#> z3 0.871 0.011 82.705 0.000
#> Y =~
#> y1 0.915 0.010 94.080 0.000
#> y2 0.852 0.013 65.821 0.000
#> y3 0.866 0.012 69.595 0.000
#> W =~
#> w1 0.916 0.010 88.332 0.000
#> w2 0.834 0.013 66.117 0.000
#> w3 0.878 0.014 60.905 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.293 0.020 14.518 0.000
#> Z 0.444 0.043 10.358 0.000
#> W ~
#> X 0.393 0.039 10.027 0.000
#> Z 0.248 0.056 4.425 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .Y 0.010 0.035 0.280 0.779
#> .W 0.010 0.032 0.310 0.757
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.175 0.011 15.874 0.000
#> Y~X ~~
#> Y~1 -0.004 0.006 -0.622 0.534
#> Y~Z ~~
#> Y~1 -0.025 0.014 -1.822 0.068
#> Y~X 0.012 0.008 1.590 0.112
#> W~X ~~
#> W~1 0.003 0.011 0.281 0.779
#> W~Z ~~
#> W~1 0.009 0.011 0.850 0.395
#> W~X 0.013 0.014 0.982 0.326
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.458 0.049 9.391 0.000
#> .W 0.447 0.062 7.164 0.000
#> .x1 0.140 0.017 8.027 0.000
#> .x2 0.317 0.019 16.312 0.000
#> .x3 0.228 0.012 18.886 0.000
#> .z1 0.161 0.019 8.521 0.000
#> .z2 0.306 0.021 14.291 0.000
#> .z3 0.241 0.018 13.223 0.000
#> .y1 0.162 0.018 9.154 0.000
#> .y2 0.274 0.022 12.516 0.000
#> .y3 0.250 0.021 11.645 0.000
#> .w1 0.160 0.019 8.444 0.000
#> .w2 0.305 0.021 14.430 0.000
#> .w3 0.229 0.025 9.110 0.000
#> Y~1 0.086 0.019 4.425 0.000
#> Y~X 0.018 0.006 3.141 0.002
#> Y~Z 0.105 0.019 5.433 0.000
#> W~1 0.059 0.013 4.684 0.000
#> W~X 0.095 0.016 5.760 0.000
#> W~Z 0.144 0.025 5.831 0.000fit_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 72.758 0.000
#> x2 0.818 0.012 70.376 0.000
#> x3 0.888 0.012 71.849 0.000
#> Z =~
#> z1 0.917 0.011 82.699 0.000
#> z2 0.845 0.013 63.888 0.000
#> z3 0.871 0.011 76.727 0.000
#> Y =~
#> y1 0.918 0.011 84.803 0.000
#> y2 0.843 0.015 57.262 0.000
#> y3 0.869 0.013 64.376 0.000
#> W =~
#> w1 0.914 0.012 78.395 0.000
#> w2 0.825 0.019 43.281 0.000
#> w3 0.886 0.016 56.650 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Y ~
#> X 0.290 0.023 12.752 0.000
#> Z 0.451 0.047 9.671 0.000
#> W ~
#> X 0.391 0.042 9.244 0.000
#> Z 0.245 0.059 4.138 0.000
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .Y 0.011 0.040 0.276 0.783
#> .W 0.009 0.033 0.268 0.788
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> X ~~
#> Z 0.168 0.013 12.905 0.000
#> Y~X ~~
#> Y~1 -0.006 0.005 -1.242 0.214
#> Y~Z ~~
#> Y~1 -0.024 0.013 -1.829 0.067
#> Y~X 0.012 0.008 1.524 0.128
#> W~X ~~
#> W~1 0.004 0.011 0.323 0.746
#> W~Z ~~
#> W~1 0.009 0.011 0.831 0.406
#> W~X 0.016 0.012 1.376 0.169
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> X 1.000
#> Z 1.000
#> .Y 0.465 0.056 8.339 0.000
#> .W 0.453 0.051 8.799 0.000
#> .x1 0.130 0.024 5.440 0.000
#> .x2 0.331 0.019 17.413 0.000
#> .x3 0.211 0.022 9.636 0.000
#> .z1 0.159 0.020 7.758 0.000
#> .z2 0.286 0.022 12.801 0.000
#> .z3 0.242 0.020 12.299 0.000
#> .y1 0.156 0.020 7.856 0.000
#> .y2 0.289 0.025 11.690 0.000
#> .y3 0.246 0.023 10.494 0.000
#> .w1 0.165 0.021 7.773 0.000
#> .w2 0.319 0.031 10.229 0.000
#> .w3 0.215 0.028 7.777 0.000
#> Y~1 0.080 0.017 4.673 0.000
#> Y~X 0.018 0.005 3.508 0.000
#> Y~Z 0.102 0.015 6.737 0.000
#> W~1 0.055 0.015 3.644 0.000
#> W~X 0.099 0.018 5.415 0.000
#> W~Z 0.142 0.028 5.054 0.000fit_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 136.498 0.000
#> y2 0.886 0.009 93.458 0.000
#> y3 0.902 0.008 114.737 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.238 0.006 42.342 0.000
#> x2 0.162 0.005 31.859 0.000
#> x3 0.077 0.005 14.336 0.000
#> w1 0.128 0.039 3.318 0.001
#> w2 0.091 0.041 2.232 0.026
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .f -0.013 0.035 -0.356 0.722
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.104 0.010 10.850 0.000
#> x3 0.004 0.010 0.444 0.657
#> w1 0.000
#> w2 0.000
#> x2 ~~
#> x3 0.097 0.014 7.083 0.000
#> w1 0.000
#> w2 0.000
#> x3 ~~
#> w1 0.000
#> w2 0.000
#> w1 ~~
#> w2 -0.041 0.048 -0.857 0.392
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.256 0.037 6.994 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.109 0.013 8.331 0.000
#> .y2 0.215 0.017 12.794 0.000
#> .y3 0.186 0.014 13.117 0.000
#> f~1 0.621 0.040 15.429 0.000fit_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.010 90.683 0.000
#> y2 0.888 0.014 64.297 0.000
#> y3 0.899 0.017 53.861 0.000
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> f ~
#> x1 0.234 0.006 37.993 0.000
#> x2 0.154 0.005 29.110 0.000
#> x3 0.078 0.007 10.795 0.000
#> w1 0.118 0.038 3.101 0.002
#> w2 0.079 0.045 1.764 0.078
#>
#> Intercepts:
#> Estimate Std.Error z.value P(>|z|)
#> .f -0.011 0.035 -0.331 0.741
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> x1 ~~
#> x2 0.110 0.011 9.893 0.000
#> x3 0.012 0.011 1.111 0.267
#> w1 0.001 0.004 0.208 0.835
#> w2 0.001 0.003 0.327 0.743
#> x2 ~~
#> x3 0.099 0.012 8.351 0.000
#> w1 -0.003 0.003 -1.022 0.307
#> w2 -0.001 0.003 -0.425 0.671
#> x3 ~~
#> w1 -0.003 0.003 -1.080 0.280
#> w2 0.003 0.003 1.002 0.316
#> w1 ~~
#> w2 -0.025 0.043 -0.571 0.568
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .f 0.315 0.032 9.811 0.000
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> w1 1.000
#> w2 1.000
#> .y1 0.115 0.019 5.878 0.000
#> .y2 0.212 0.025 8.634 0.000
#> .y3 0.191 0.030 6.369 0.000
#> f~1 0.569 0.034 16.725 0.000