# Multilevel Models with plssem

This vignette shows examples of multilevel random slopes and intercept models, with both continuous and ordinal data.

## Random Slopes Model

    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)
    "

### Continuous Indicators

    fit_slopes_cont <- pls(
      slopes_model,
      data      = randomSlopes,
      bootstrap = TRUE,
      boot.R    = 50
    )
    summary(fit_slopes_cont)

### Ordered Indicators

    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)

## Random Intercepts Model

    intercepts_model <- '
      f =~ y1 + y2 + y3
      f ~ x1 + x2 + x3 + w1 + w2 + (1 | cluster)
    '

### Continuous Indicators

    fit_intercepts_cont <- pls(
      intercepts_model,
      data      = randomIntercepts,
      bootstrap = TRUE,
      boot.R    = 50
    )
    summary(fit_intercepts_cont)

### Ordered Indicators

    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)