##### Load required package.
library(mvtnorm)
##### Generate ordinal data from the GPCM
#####
##### Item parameter generation
set.seed(123)
GPCMa <- runif(10, 0.8, 2)
GPCMb <- vector("list", 10)
for(i in 1:10) GPCMb[[i]] <- -c(runif(1, -3, -2),
runif(1, -1.5, -0.5),
runif(1, 0, 1),
runif(1, 1.5, 2.5))
GMCMa2d <- matrix(0, nrow = 10, ncol = 2)
GMCMa2d[1:5, 1] <- GPCMa[1:5]
GMCMa2d[6:10, 2] <- GPCMa[6:10]
##### Latent variables in two groups
n <- 200
set.seed(1234)
covmat2d <- diag(rep(1, 2))
covmat2d[!diag(2)] <- 0.6
latmat2dA <- rmvnorm(n, c(0, 0), covmat2d)
latmat2dB <- rmvnorm(n, c(1, 1), covmat2d)
##### Observed data
set.seed(12345)
dataGPCM2d <- matrix(NA, nrow = 2 * n, ncol = 10)
dataGPCM2d[1:n, ] <- DGP(GMCMa2d, GPCMb, rep("GPCM", 10),
latmat2dA)
dataGPCM2d[(n + 1):(2 * n), ] <- DGP(GMCMa2d, GPCMb,
rep("GPCM", 10), latmat2dB)
##### Setup two-dimensional independent-clusters model
mydim2d <- matrix(NA, nrow = 10, ncol = 2)
mydim2d[1:5, 1] <- 1
mydim2d[6:10, 2] <- 1
##### Lap(2)
estLap2 <- lamle(y = dataGPCM2d[1:n,], model = mydim2d,
modeltype = rep(c("GPCM", "GRM"), 5),
method = "lap", accuracy = 2, optimizer =
"BFGS", inithess = "crossprod")
lamle.plot(estLap2, toplot = "TIF", variables = 1:5)
lamle.plot(estLap2, toplot = "prob", variables = 5)
Run the code above in your browser using DataLab