Overview

Within this document, we highlight the different features of the simcdm package as it relates to simulating cognitive diagnostic modeling data.

Notation

For consistency, we aim to use the following notation.

Denoting individuals:

  • NN is the total number of individuals taking the assessment.
  • ii is the current individual.

Denoting items:

  • JJ is the total number of items on the assessment.
  • jj is the current item
  • YijY_{ij} is the observed binary response for individual ii (1≤i≤N1\leq i \leq N) to item jj (1≤j≤J1\leq j\leq J).
  • sjs_j is the probability of slipping on item jj.
  • gjg_j is the probability of guessing on item jj.

Denoting attributes:

  • KK is the total number of attributes for the assessment item.
  • kk is the current attribute.
  • 𝛂i=(αi1,…,αiK)′\boldsymbol\alpha_i=\left(\alpha_{i1},\dots,\alpha_{iK}\right)^\prime where 𝛂i∈{0,1}K\boldsymbol\alpha_i\in \left\{0,1\right\}^K and αik\alpha_{ik} is the latent binary attribute for individual ii on attribute kk (1≤k≤K1\leq k\leq K).

Denoting the skill/attribute “Q” matrix:

  • 𝐪j=(qj1,…,qjK)′\boldsymbol q_{j}=\left(q_{j1},\dots,q_{jK}\right)^\prime be the jjth row of 𝐐\boldsymbol Q such that qjk=1q_{jk}=1 if attribute kk is required for item jj and zero otherwise.

Usage

To use simcdm, please load the package.

Matrix Simulation

Simulations within this section are done underneath the following settings.

# Set a seed for reproducibility
set.seed(888)

# Setup Parameters
N = 15   # Number of Examinees / Subjects
J = 10   # Number of Items
K = 2    # Number of Skills / Attributes

Identifiable Q Matrix Simulation

Simulate an identifiable QQ matrix (JJ items by KK skills).

# Set a seed for reproducibility
set.seed(1512)

# Simulate an identifiable Q matrix
Q = sim_q_matrix(J, K)
Q
##       [,1] [,2]
##  [1,]    1    0
##  [2,]    1    0
##  [3,]    0    1
##  [4,]    0    1
##  [5,]    0    1
##  [6,]    0    1
##  [7,]    1    1
##  [8,]    1    0
##  [9,]    1    0
## [10,]    0    1

η\eta Matrix Simulation

Create the ideal response matrix for each trait (JJ items by 2K2^K latent classes).

# Set a seed for reproducibility
set.seed(4421)

# Simulate an eta matrix
eta = sim_eta_matrix(K, J, Q)
eta
##       [,1] [,2] [,3] [,4]
##  [1,]    0    0    1    1
##  [2,]    0    0    1    1
##  [3,]    0    1    0    1
##  [4,]    0    1    0    1
##  [5,]    0    1    0    1
##  [6,]    0    1    0    1
##  [7,]    0    0    0    1
##  [8,]    0    0    1    1
##  [9,]    0    0    1    1
## [10,]    0    1    0    1

Attribute profile simulation

Generate latent attribute profile classes (2K2^K latent classes by KK skills).

# Create a listing of all attribute classes 
class_alphas = attribute_classes(K)
class_alphas
##      [,1] [,2]
## [1,]    0    0
## [2,]    0    1
## [3,]    1    0
## [4,]    1    1

Generate latent attribute profile class for each subject (NN subjects by KK skills).

# Set a seed for reproducibility
set.seed(5126)

# Create attributes for a subject 
subject_alphas = sim_subject_attributes(N, K)
subject_alphas
##       [,1] [,2]
##  [1,]    0    0
##  [2,]    1    1
##  [3,]    1    0
##  [4,]    1    1
##  [5,]    0    0
##  [6,]    0    1
##  [7,]    0    1
##  [8,]    1    0
##  [9,]    0    1
## [10,]    0    1
## [11,]    0    1
## [12,]    0    1
## [13,]    1    0
## [14,]    0    0
## [15,]    1    0
# Equivalent to:
# subject_alphas = class_alphas[sample(2 ^ K, N, replace = TRUE),]

DINA Simulation

Simulations within this section are done underneath the following settings.

# Set a seed for reproducibility
set.seed(888)

# Setup Parameters
N = 15   # Number of Examinees / Subjects
J = 10   # Number of Items
K = 2    # Number of Skills / Attributes

# Assign slipping and guessing values for each item
ss = gs = rep(.2, J)

# Simulate identifiable Q matrix
Q = sim_q_matrix(J, K)

# Simulate subject attributes
subject_alphas = sim_subject_attributes(N, K)

DINA Item Simulation

Simulate item data, YY, under DINA model (NN by JJ)

# Set a seed for reproducibility
set.seed(2019)

# Simulate items under the DINA model
items_dina = sim_dina_items(subject_alphas, Q, ss, gs)
items_dina
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
##  [1,]    0    0    0    1    1    0    0    0    1     1
##  [2,]    1    1    1    0    1    1    1    1    0     1
##  [3,]    0    0    0    0    1    0    0    0    1     1
##  [4,]    1    1    1    0    0    0    1    1    1     0
##  [5,]    1    1    1    1    1    1    1    1    1     1
##  [6,]    1    1    1    1    0    1    0    1    0     1
##  [7,]    0    0    0    1    1    0    0    0    0     1
##  [8,]    1    0    1    1    1    0    0    1    0     1
##  [9,]    1    1    1    1    0    1    1    1    1     1
## [10,]    0    1    0    1    1    0    0    0    1     1
## [11,]    1    1    1    1    1    1    1    0    1     1
## [12,]    0    0    0    0    1    0    0    0    1     0
## [13,]    0    0    0    0    1    0    0    0    1     1
## [14,]    1    0    0    1    1    0    0    0    0     0
## [15,]    1    1    0    1    0    0    1    1    0     0

DINA Attribute Simulation

Simulate attribute data under DINA model (NN by JJ)

# Set a seed for reproducibility
set.seed(51823)

# Simulate attributes under the DINA model
attributes = sim_dina_attributes(subject_alphas, Q)
attributes
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
##  [1,]    0    0    0    1    1    0    0    0    1     1
##  [2,]    1    1    1    1    1    1    1    1    1     1
##  [3,]    0    0    0    1    1    0    0    0    1     1
##  [4,]    1    1    1    0    0    0    1    1    0     0
##  [5,]    1    1    1    1    1    1    1    1    1     1
##  [6,]    1    1    1    1    1    1    1    1    1     1
##  [7,]    0    0    0    1    1    0    0    0    1     1
##  [8,]    1    1    1    1    1    1    1    1    1     1
##  [9,]    1    1    1    1    1    1    1    1    1     1
## [10,]    0    0    0    1    1    0    0    0    1     1
## [11,]    1    1    1    1    1    1    1    1    1     1
## [12,]    0    0    0    1    1    0    0    0    1     1
## [13,]    0    0    0    1    1    0    0    0    1     1
## [14,]    0    0    0    0    0    0    0    0    0     0
## [15,]    1    1    1    0    0    0    1    1    0     0

rRUM Simulation

The rRUM simulations are done using the following settings.

# Set a seed for reproducibility
set.seed(888)

# Setup Parameters
N = 15   # Number of Examinees / Subjects
J = 10   # Number of Items
K = 2    # Number of Skills / Attributes

# The probabilities of answering each item correctly for individuals 
# who do not lack any required attribute
pistar = rep(.9, J)

# Simulate an identifiable Q matrix
Q = sim_q_matrix(J, K)

# Penalties for failing to have each of the required attributes
rstar  = .5 * Q

# Latent Class Probabilities
pis = c(.1, .2, .3, .4)

# Generate latent attribute profile with custom probability (N subjects by K skills)
subject_alphas = sim_subject_attributes(N, K, prob = pis)

# Equivalent to:
# class_alphas = attribute_classes(K)
# subject_alphas = class_alphas[sample(2 ^ K, N, replace = TRUE, prob = pis),]

Simulate rRUM items

Simulate rRUM item data YY (NN by JJ)

# Set a seed for reproducibility
set.seed(912)

# Generate rRUM items
rrum_items = sim_rrum_items(Q, rstar, pistar, subject_alphas)
rrum_items
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
##  [1,]    1    1    1    0    1    0    1    1    1     0
##  [2,]    1    1    0    1    1    0    1    0    0     0
##  [3,]    0    1    1    1    0    1    1    1    0     0
##  [4,]    0    1    1    1    0    1    1    1    1     0
##  [5,]    1    1    0    0    1    0    1    1    1     0
##  [6,]    1    1    1    1    0    0    1    1    0     1
##  [7,]    1    0    1    0    1    0    0    0    0     1
##  [8,]    0    0    1    0    0    0    1    0    0     1
##  [9,]    0    1    0    1    1    1    0    1    1     0
## [10,]    1    1    1    1    0    0    0    1    1     0
## [11,]    1    1    1    0    0    0    1    1    0     1
## [12,]    0    1    0    1    1    0    1    1    1     1
## [13,]    1    0    1    1    1    0    1    1    1     1
## [14,]    1    0    1    1    1    1    1    1    1     1
## [15,]    0    0    1    0    1    1    1    1    1     1