This function returns an integer matrix of simulated responses under given item and person parameters.
sim_gpcm(thres, alpha, theta)################# simulate GPCM ###############################################
set.seed(1750)
THRES <- matrix(c(-2,-1.23,1.11,3.48,1
,2,-1,-0.2,0.5,1.3,-0.8,1.5),nrow=2)
# slopes
sl <- c(0.5,1,1.5,1.1,1,0.98)
THRESx <- rbind(0,THRES)
THETA <- rnorm(100)
simdat_gpcm <- sim_gpcm(thres = THRESx,alpha = sl,theta = THETA)
head(simdat_gpcm)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 2 0 0 0 0 1
#> [2,] 2 1 0 1 0 0
#> [3,] 2 0 1 2 1 1
#> [4,] 2 0 1 2 1 1
#> [5,] 1 0 1 2 2 2
#> [6,] 1 0 1 1 2 0
### simulate with a different number of categories
THRES1 <- rbind(THRESx,c(NA,NA,NA,NA,1.7,1))
THRES1 # last 2 items have +1 category
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.00 0.00 0 0.0 0.0 0.0
#> [2,] -2.00 1.11 1 -1.0 0.5 -0.8
#> [3,] -1.23 3.48 2 -0.2 1.3 1.5
#> [4,] NA NA NA NA 1.7 1.0
simdat_gpcm2 <- sim_gpcm(thres = THRES1,alpha = sl,theta = THETA)
head(simdat_gpcm2)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 2 0 0 0 0 0
#> [2,] 1 1 0 2 0 2
#> [3,] 2 0 0 1 2 2
#> [4,] 2 1 1 2 2 0
#> [5,] 2 1 1 2 3 3
#> [6,] 2 0 0 2 0 1
# check the maximum category
apply(simdat_gpcm2,2,max)
#> [1] 2 2 2 2 3 3