if (FALSE) {
####################################################
# 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",gs.args = list (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,gs.args = list(type="random"))
# simulated data
extract(sim,what = "dat")
# simulated attributes
extract(sim,what = "attribute")
####################################################
# Example 5a #
# 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 5b #
# Data simulation (all CDMs) #
# using probability of success in list format #
# attribute has a linear structure #
####################################################
est <- GDINA(sim10GDINA$simdat,sim10GDINA$simQ,att.str = list(c(1,2),c(2,3)))
# design matrix
# link function
# item probabilities
ip <- extract(est,"itemprob.parm")
sim <- simGDINA(N=500,sim10GDINA$simQ,catprob.parm = ip,
design.matrix = dm,linkfunc = lf,att.str = list(c(1,2),c(2,3)))
####################################################
# Example 6a #
# 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
sim <- simGDINA(N,Q,delta.parm = delta.list, model = model)
####################################################
# Example 6b #
# Data simulation (all CDMs) #
# using delta parameters in list format #
# attribute has a linear structure #
####################################################
est <- GDINA(sim10GDINA$simdat,sim10GDINA$simQ,att.str = list(c(1,2),c(2,3)))
# design matrix
# link function
# item probabilities
ip <- extract(est,"delta.parm")
sim <- simGDINA(N=500,sim10GDINA$simQ,delta.parm = d,
design.matrix = dm,linkfunc = lf,att.str = list(c(1,2),c(2,3)))
####################################################
# 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
# data simulation
gs <- matrix(0.1,nrow(Q),2)
simD <- simGDINA(N,Q,gs.parm = gs,
model = "DINA",att.dist = "categorical",att.prior = struc$att.prob)
####################################################
# 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",gs.args=list(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 = "GDINA")
# 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")
####################################################
# Example 13
# DINA model Attribute generated using
# categorical distribution
####################################################
Q <- sim10GDINA$simQ
gs <- matrix(0.1,nrow(Q),2)
N <- 5000
set.seed(12345)
prior <- c(0.1,0.2,0,0,0.2,0,0,0.5)
sim <- simGDINA(N,Q,gs.parm = gs, model="DINA", att.dist = "categorical",att.prior = prior)
# check latent class sizes
table(sim$att.group)/N
####################################################
# Example 14
# MS-DINA model
####################################################
Q <- matrix(c(1,1,1,1,0,
1,2,0,1,1,
2,1,1,0,0,
3,1,0,1,0,
4,1,0,0,1,
5,1,1,0,0,
5,2,0,0,1),ncol = 5,byrow = TRUE)
d <- list(
item1=c(0.2,0.7),
item2=c(0.1,0.6),
item3=c(0.2,0.6),
item4=c(0.2,0.7),
item5=c(0.1,0.8))
set.seed(12345)
sim <- simGDINA(N=1000,Q = Q, delta.parm = d,
model = c("MSDINA","MSDINA","DINA","DINA","DINA","MSDINA","MSDINA"))
# simulated data
extract(sim,what = "dat")
# simulated attributes
extract(sim,what = "attribute")
##############################################################
# Example 15
# reparameterized SISM model (Kuo, Chen, & de la Torre, 2018)
# see GDINA function for more details
###############################################################
# The Q-matrix used in Kuo, et al (2018)
# The first four columns are for Attributes 1-4
# The last three columns are for Bugs 1-3
Q <- matrix(c(1,0,0,0,0,0,0,
0,1,0,0,0,0,0,
0,0,1,0,0,0,0,
0,0,0,1,0,0,0,
0,0,0,0,1,0,0,
0,0,0,0,0,1,0,
0,0,0,0,0,0,1,
1,0,0,0,1,0,0,
0,1,0,0,1,0,0,
0,0,1,0,0,0,1,
0,0,0,1,0,1,0,
1,1,0,0,1,0,0,
1,0,1,0,0,0,1,
1,0,0,1,0,0,1,
0,1,1,0,0,0,1,
0,1,0,1,0,1,1,
0,0,1,1,0,1,1,
1,0,1,0,1,1,0,
1,1,0,1,1,1,0,
0,1,1,1,1,1,0),ncol = 7,byrow = TRUE)
J <- nrow(Q)
N <- 500
gs <- data.frame(guess=rep(0.1,J),slip=rep(0.1,J))
sim <- simGDINA(N,Q,gs.parm = gs,model = "SISM",no.bugs=3)
# 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")
}
Run the code above in your browser using DataLab