# Logistic mixed model with factor loadings, example from PLmixed
data("IRTsim", package = "PLmixed")
# Reduce data size for the example to run faster
IRTsub <- IRTsim[IRTsim$item < 4, ]
IRTsub <- IRTsub[sample(nrow(IRTsub), 300), ]
IRTsub$item <- factor(IRTsub$item)
# Fix loading for first item to 1, and estimate the two others freely
loading_matrix <- matrix(c(1, NA, NA), ncol = 1)
# Estimate model
mod <- galamm(y ~ item + (0 + ability | sid) + (0 + ability | school),
data = IRTsub, family = binomial, load.var = "item",
factor = "ability", lambda = loading_matrix
)
# Show estimated factor loadings, with standard errors
factor_loadings(mod)
Run the code above in your browser using DataLab