## Not run: ------------------------------------
# ####################################################
# # Example 1 #
# # Data simulation (DINA) #
# ####################################################
# N <- 500
# Q <- sim30GDINA$simQ
# J <- nrow(Q)
# gs <- data.frame(guess=rep(0.1,J),slip=rep(0.1,J))
#
# # Simulated DINA model; to simulate G-DINA model
# # and other CDMs, change model argument accordingly
#
# sim <- simGDINA(N,Q,gs.parm = gs,model = "DINA")
#
# # True item success probabilities
# extract(sim,what = "catprob.parm")
#
# # True delta parameters
# extract(sim,what = "delta.parm")
#
# # simulated data
# extract(sim,what = "dat")
#
# # simulated attributes
# extract(sim,what = "attribute")
#
#
# ####################################################
# # Example 2 #
# # Data simulation (RRUM) #
# ####################################################
# N <- 500
# Q <- sim30GDINA$simQ
# J <- nrow(Q)
# gs <- data.frame(guess=rep(0.2,J),slip=rep(0.2,J))
# # Simulated RRUM
# # deltas except delta0 for each item will be simulated
# # randomly subject to the constraints of RRUM
# sim <- simGDINA(N,Q,gs.parm = gs,model = "RRUM")
#
# # simulated data
# extract(sim,what = "dat")
#
# # simulated attributes
# extract(sim,what = "attribute")
#
# ####################################################
# # Example 3 #
# # Data simulation (LLM) #
# ####################################################
# N <- 500
# Q <- sim30GDINA$simQ
# J <- nrow(Q)
# gs <- data.frame(guess=rep(0.1,J),slip=rep(0.1,J))
# # Simulated LLM
# # By specifying type="equal", each required attribute is
# # assumed to contribute to logit(P) equally
# sim <- simGDINA(N,Q,gs.parm = gs,model = "LLM",type="equal")
# #check below for what the equal contribution means
# extract(sim,what = "delta.parm")
#
# # simulated data
# extract(sim,what = "dat")
#
# # simulated attributes
# extract(sim,what = "attribute")
#
# ####################################################
# # Example 4 #
# # Data simulation (all CDMs) #
# ####################################################
#
# set.seed(12345)
#
# N <- 500
# Q <- sim10GDINA$simQ
# J <- nrow(Q)
# gs <- data.frame(guess=rep(0.1,J),slip=rep(0.1,J))
# # Simulated different CDMs for different items
# models <- c("GDINA","DINO","DINA","ACDM","LLM","RRUM","GDINA","LLM","RRUM","DINA")
# sim <- simGDINA(N,Q,gs.parm = gs,model = models,type="random")
#
# # simulated data
# extract(sim,what = "dat")
#
# # simulated attributes
# extract(sim,what = "attribute")
#
# ####################################################
# # Example 5 #
# # Data simulation (all CDMs) #
# # using probability of success in list format #
# ####################################################
#
# # success probabilities for each item need to be provided in list format as follows:
# # if item j requires Kj attributes, 2^Kj success probabilities
# # need to be specified
# # e.g., item 1 only requires 1 attribute
# # therefore P(0) and P(1) should be specified;
# # similarly, item 10 requires 3 attributes,
# # P(000),P(100),P(010)...,P(111) should be specified;
# # the latent class represented by each element can be obtained
# # by calling attributepattern(Kj)
# itemparm.list <- list(item1=c(0.2,0.9),
# item2=c(0.1,0.8),
# item3=c(0.1,0.9),
# item4=c(0.1,0.3,0.5,0.9),
# item5=c(0.1,0.1,0.1,0.8),
# item6=c(0.2,0.9,0.9,0.9),
# item7=c(0.1,0.45,0.45,0.8),
# item8=c(0.1,0.28,0.28,0.8),
# item9=c(0.1,0.4,0.4,0.8),
# item10=c(0.1,0.2,0.3,0.4,0.4,0.5,0.7,0.9))
# set.seed(12345)
# N <- 500
# Q <- sim10GDINA$simQ
# # When simulating data using catprob.parm argument,
# # it is not necessary to specify model and type
# sim <- simGDINA(N,Q,catprob.parm = itemparm.list)
#
#
# ####################################################
# # Example 6 #
# # Data simulation (all CDMs) #
# # using delta parameters in list format #
# ####################################################
#
# delta.list <- list(c(0.2,0.7),
# c(0.1,0.7),
# c(0.1,0.8),
# c(0.1,0.7),
# c(0.1,0.8),
# c(0.2,0.3,0.2,0.1),
# c(0.1,0.35,0.35),
# c(-1.386294,0.9808293,1.791759),
# c(-1.609438,0.6931472,0.6),
# c(0.1,0.1,0.2,0.3,0.0,0.0,0.1,0.1))
#
# model <- c("GDINA","GDINA","GDINA","DINA","DINO","GDINA","ACDM","LLM","RRUM","GDINA")
# N <- 500
# Q <- sim10GDINA$simQ
# # When simulating using delta.parm argument, model needs to be
# # specified
# sim <- simGDINA(N,Q,delta.parm = delta.list, model = model)
#
#
# ####################################################
# # Example 7 #
# # Data simulation (higher order DINA model) #
# ####################################################
#
# Q <- sim30GDINA$simQ
# gs <- matrix(0.1,nrow(Q),2)
# N <- 500
# set.seed(12345)
# theta <- rnorm(N)
# K <- ncol(Q)
# lambda <- data.frame(a=rep(1,K),b=seq(-2,2,length.out=K))
# sim <- simGDINA(N,Q,gs.parm = gs, model="DINA", att.dist = "higher.order",
# higher.order.parm = list(theta = theta,lambda = lambda))
#
# ####################################################
# # Example 8 #
# # Data simulation (higher-order CDMs) #
# ####################################################
#
# Q <- sim30GDINA$simQ
# gs <- matrix(0.1,nrow(Q),2)
# models <- c(rep("GDINA",5),
# rep("DINO",5),
# rep("DINA",5),
# rep("ACDM",5),
# rep("LLM",5),
# rep("RRUM",5))
# N <- 500
# set.seed(12345)
# theta <- rnorm(N)
# K <- ncol(Q)
# lambda <- data.frame(a=runif(K,0.7,1.3),b=seq(-2,2,length.out=K))
# sim <- simGDINA(N,Q,gs.parm = gs, model=models, att.dist = "higher.order",
# higher.order.parm = list(theta = theta,lambda = lambda))
#
#
# ####################################################
# # Example 9 #
# # Data simulation (higher-order model) #
# # using the multivariate normal threshold model #
# ####################################################
#
#
# # See Chiu et al., (2009)
#
# N <- 500
# Q <- sim10GDINA$simQ
# K <- ncol(Q)
# gs <- matrix(0.1,nrow(Q),2)
# cutoffs <- qnorm(c(1:K)/(K+1))
# m <- rep(0,K)
# vcov <- matrix(0.5,K,K)
# diag(vcov) <- 1
# simMV <- simGDINA(N,Q,gs.parm = gs, att.dist = "mvnorm",
# mvnorm.parm=list(mean = m, sigma = vcov,cutoffs = cutoffs))
#
# ####################################
# # Example 10 #
# # Simulation using #
# # user-specified att structure#
# ####################################
#
# # --- User-specified attribute structure ----#
# Q <- sim30GDINA$simQ
# K <- ncol(Q)
# # divergent structure A1->A2->A3;A1->A4->A5;A1->A4->A6
# diverg <- list(c(1,2),
# c(2,3),
# c(1,4),
# c(4,5))
# struc <- att.structure(diverg,K)
#
# # data simulation
# N <- 1000
# true.lc <- sample(c(1:2^K),N,replace=TRUE,prob=struc$att.prob)
# table(true.lc) #check the sample
# true.att <- attributepattern(K)[true.lc,]
# gs <- matrix(rep(0.1,2*nrow(Q)),ncol=2)
# # data simulation
# simD <- simGDINA(N,Q,gs.parm = gs,
# model = "DINA",attribute = true.att)
#
#
# ####################################################
# # Example 11 #
# # Data simulation #
# # (GDINA with monotonicity constraints) #
# ####################################################
#
# set.seed(12345)
#
# N <- 500
# Q <- sim30GDINA$simQ
# J <- nrow(Q)
# gs <- data.frame(guess=rep(0.1,J),slip=rep(0.1,J))
# # Simulated different CDMs for different items
# sim <- simGDINA(N,Q,gs.parm = gs,model = "GDINA",mono.constraint=TRUE)
#
# # True item success probabilities
# extract(sim,what = "catprob.parm")
#
# # True delta parameters
# extract(sim,what = "delta.parm")
#
# # simulated data
# extract(sim,what = "dat")
#
# # simulated attributes
# extract(sim,what = "attribute")
#
# ####################################################
# # Example 12 #
# # Data simulation #
# # (Sequential G-DINA model - polytomous responses) #
# ####################################################
#
# set.seed(12345)
#
# N <- 2000
# # restricted Qc matrix
# Qc <- sim20seqGDINA$simQ
# #total number of categories
# J <- nrow(Qc)
# gs <- data.frame(guess=rep(0.1,J),slip=rep(0.1,J))
# # simulate sequential DINA model
# simseq <- simGDINA(N, Qc, sequential = TRUE, gs.parm = gs, model = "DINA")
#
# # True item success probabilities
# extract(simseq,what = "catprob.parm")
#
# # True delta parameters
# extract(simseq,what = "delta.parm")
#
# # simulated data
# extract(simseq,what = "dat")
#
# # simulated attributes
# extract(simseq,what = "attribute")
## ---------------------------------------------
Run the code above in your browser using DataLab