Title: | Simulate Cognitive Diagnostic Model ('CDM') Data |
---|---|
Description: | Provides efficient R and 'C++' routines to simulate cognitive diagnostic model data for Deterministic Input, Noisy "And" Gate ('DINA') and reduced Reparameterized Unified Model ('rRUM') from Culpepper and Hudson (2017) <doi: 10.1177/0146621617707511>, Culpepper (2015) <doi:10.3102/1076998615595403>, and de la Torre (2009) <doi:10.3102/1076998607309474>. |
Authors: | James Joseph Balamuta [aut, cre, cph] , Steven Andrew Culpepper [aut, cph] , Aaron Hudson [ctb, cph] |
Maintainer: | James Joseph Balamuta <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.2 |
Built: | 2024-11-06 04:43:03 UTC |
Source: | https://github.com/tmsalab/simcdm |
Provides efficient R and 'C++' routines to simulate cognitive diagnostic model data for Deterministic Input, Noisy "And" Gate ('DINA') and reduced Reparameterized Unified Model ('rRUM') from Culpepper and Hudson (2017) doi: 10.1177/0146621617707511, Culpepper (2015) doi:10.3102/1076998615595403, and de la Torre (2009) doi:10.3102/1076998607309474.
Maintainer: James Joseph Balamuta [email protected] (ORCID) [copyright holder]
Authors:
Steven Andrew Culpepper [email protected] (ORCID) [copyright holder]
Other contributors:
Aaron Hudson [email protected] (ORCID) [contributor, copyright holder]
Useful links:
Report bugs at https://github.com/tmsalab/simcdm/issues
Computes the powers of 2 from up to
for
-dimensional attribute pattern.
attribute_bijection(K)
attribute_bijection(K)
K |
Number of Attributes. |
A vec
with length detailing the power's of 2.
Steven Andrew Culpepper and James Joseph Balamuta
## Construct an attribute bijection ---- biject = attribute_bijection(3)
## Construct an attribute bijection ---- biject = attribute_bijection(3)
in
Matrix formGenerate the
attribute profile matrix for members of class
such that
' is 1 if members of class
possess skill
and zero otherwise.
attribute_classes(K)
attribute_classes(K)
K |
Number of Attributes |
A by
matrix
of latent classes
corresponding to entry of
based upon
mastery and nonmastery of the
skills.
James Joseph Balamuta and Steven Andrew Culpepper
sim_subject_attributes()
and attribute_inv_bijection()
## Simulate Attribute Class Matrix ---- # Define number of attributes K = 3 # Generate an Latent Attribute Profile (Alpha) Matrix alphas = attribute_classes(K)
## Simulate Attribute Class Matrix ---- # Define number of attributes K = 3 # Generate an Latent Attribute Profile (Alpha) Matrix alphas = attribute_classes(K)
Convert an integer between and
to
-dimensional attribute pattern.
attribute_inv_bijection(K, CL)
attribute_inv_bijection(K, CL)
K |
Number of Attributes. |
CL |
An |
A -dimensional vector with an attribute pattern corresponding
to
CL
.
Steven Andrew Culpepper and James Joseph Balamuta
## Construct an attribute inversion bijection ---- inv_biject1 = attribute_inv_bijection(5, 1) inv_biject2 = attribute_inv_bijection(5, 2)
## Construct an attribute inversion bijection ---- inv_biject1 = attribute_inv_bijection(5, 1) inv_biject2 = attribute_inv_bijection(5, 2)
MatrixGenerates a DINA model's matrix based on alphas and
the
matrix.
sim_dina_attributes(alphas, Q)
sim_dina_attributes(alphas, Q)
alphas |
A |
Q |
A |
The
matrix
with dimensions under
the DINA model.
Steven Andrew Culpepper and James Joseph Balamuta
sim_dina_class()
and sim_dina_items()
N = 200 K = 5 J = 30 delta0 = rep(1, 2 ^ K) # Creating Q matrix Q = matrix(rep(diag(K), 2), 2 * K, K, byrow = TRUE) for (mm in 2:K) { temp = combn(seq_len(K), m = mm) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 Q = rbind(Q, tempmat) } Q = Q[seq_len(J), ] # Setting item parameters and generating attribute profiles ss = gs = rep(.2, J) PIs = rep(1 / (2 ^ K), 2 ^ K) CLs = c((1:(2 ^ K)) %*% rmultinom(n = N, size = 1, prob = PIs)) # Defining matrix of possible attribute profiles As = rep(0, K) for (j in seq_len(K)) { temp = combn(1:K, m = j) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 As = rbind(As, tempmat) } As = as.matrix(As) # Sample true attribute profiles Alphas = As[CLs, ] # Simulate item data under DINA model dina_items = sim_dina_items(Alphas, Q, ss, gs) # Simulate attribute data under DINA model dina_attributes = sim_dina_attributes(Alphas, Q)
N = 200 K = 5 J = 30 delta0 = rep(1, 2 ^ K) # Creating Q matrix Q = matrix(rep(diag(K), 2), 2 * K, K, byrow = TRUE) for (mm in 2:K) { temp = combn(seq_len(K), m = mm) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 Q = rbind(Q, tempmat) } Q = Q[seq_len(J), ] # Setting item parameters and generating attribute profiles ss = gs = rep(.2, J) PIs = rep(1 / (2 ^ K), 2 ^ K) CLs = c((1:(2 ^ K)) %*% rmultinom(n = N, size = 1, prob = PIs)) # Defining matrix of possible attribute profiles As = rep(0, K) for (j in seq_len(K)) { temp = combn(1:K, m = j) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 As = rbind(As, tempmat) } As = as.matrix(As) # Sample true attribute profiles Alphas = As[CLs, ] # Simulate item data under DINA model dina_items = sim_dina_items(Alphas, Q, ss, gs) # Simulate attribute data under DINA model dina_attributes = sim_dina_attributes(Alphas, Q)
Generate the dichotomous item matrix for a DINA Model.
sim_dina_class(N, J, CLASS, ETA, gs, ss)
sim_dina_class(N, J, CLASS, ETA, gs, ss)
N |
Number of Observations |
J |
Number of Assessment Items |
CLASS |
Does the individual possess all the necessary attributes? |
ETA |
|
gs |
A |
ss |
A |
A dichotomous item matrix with dimensions .
Steven Andrew Culpepper and James Joseph Balamuta
sim_dina_attributes()
and sim_dina_items()
# Set N = 100 rho = 0 K = 3 # Fixed Number of Assessment Items for Q J = 18 # Specify Q qbj = c(4, 2, 1, 4, 2, 1, 4, 2, 1, 6, 5, 3, 6, 5, 3, 7, 7, 7) # Fill Q Matrix Q = matrix(, J, K) for (j in seq_len(J)) { Q[j,] = attribute_inv_bijection(K, qbj[j]) } # Item parm vals ss = gs = rep(.2, J) # Generating attribute classes depending on correlation if (rho == 0) { PIs = rep(1 / (2 ^ K), 2 ^ K) CLs = c(seq_len(2 ^ K) %*% rmultinom(n = N, size = 1, prob = PIs)) - 1 } if (rho > 0) { Z = matrix(rnorm(N * K), N, K) Sig = matrix(rho, K, K) diag(Sig) = 1 X = Z %*% chol(Sig) thvals = matrix(rep(0, K), N, K, byrow = T) Alphas = 1 * (X > thvals) CLs = Alphas %*% attribute_bijection(K) } # Simulate data under DINA model ETA = sim_eta_matrix(K, J, Q) Y_sim = sim_dina_class(N, J, CLs, ETA, gs, ss)
# Set N = 100 rho = 0 K = 3 # Fixed Number of Assessment Items for Q J = 18 # Specify Q qbj = c(4, 2, 1, 4, 2, 1, 4, 2, 1, 6, 5, 3, 6, 5, 3, 7, 7, 7) # Fill Q Matrix Q = matrix(, J, K) for (j in seq_len(J)) { Q[j,] = attribute_inv_bijection(K, qbj[j]) } # Item parm vals ss = gs = rep(.2, J) # Generating attribute classes depending on correlation if (rho == 0) { PIs = rep(1 / (2 ^ K), 2 ^ K) CLs = c(seq_len(2 ^ K) %*% rmultinom(n = N, size = 1, prob = PIs)) - 1 } if (rho > 0) { Z = matrix(rnorm(N * K), N, K) Sig = matrix(rho, K, K) diag(Sig) = 1 X = Z %*% chol(Sig) thvals = matrix(rep(0, K), N, K, byrow = T) Alphas = 1 * (X > thvals) CLs = Alphas %*% attribute_bijection(K) } # Simulate data under DINA model ETA = sim_eta_matrix(K, J, Q) Y_sim = sim_dina_class(N, J, CLs, ETA, gs, ss)
Sample responses from the DINA model for given attribute profiles, Q matrix,
and item parmeters. Returns a matrix
of dichotomous responses
generated under DINA model.
sim_dina_items(alphas, Q, ss, gs)
sim_dina_items(alphas, Q, ss, gs)
alphas |
A |
Q |
A |
ss |
A |
gs |
A |
A by
matrix
of responses from the DINA model.
Steven Andrew Culpepper and James Joseph Balamuta
sim_dina_class()
and sim_dina_attributes()
N = 200 K = 5 J = 30 delta0 = rep(1, 2 ^ K) # Creating Q matrix Q = matrix(rep(diag(K), 2), 2 * K, K, byrow = TRUE) for (mm in 2:K) { temp = combn(seq_len(K), m = mm) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 Q = rbind(Q, tempmat) } Q = Q[seq_len(J), ] # Setting item parameters and generating attribute profiles ss = gs = rep(.2, J) PIs = rep(1 / (2 ^ K), 2 ^ K) CLs = c((1:(2 ^ K)) %*% rmultinom(n = N, size = 1, prob = PIs)) # Defining matrix of possible attribute profiles As = rep(0, K) for (j in seq_len(K)) { temp = combn(1:K, m = j) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 As = rbind(As, tempmat) } As = as.matrix(As) # Sample true attribute profiles Alphas = As[CLs, ] # Simulate item data under DINA model dina_items = sim_dina_items(Alphas, Q, ss, gs) # Simulate attribute data under DINA model dina_attributes = sim_dina_attributes(Alphas, Q)
N = 200 K = 5 J = 30 delta0 = rep(1, 2 ^ K) # Creating Q matrix Q = matrix(rep(diag(K), 2), 2 * K, K, byrow = TRUE) for (mm in 2:K) { temp = combn(seq_len(K), m = mm) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 Q = rbind(Q, tempmat) } Q = Q[seq_len(J), ] # Setting item parameters and generating attribute profiles ss = gs = rep(.2, J) PIs = rep(1 / (2 ^ K), 2 ^ K) CLs = c((1:(2 ^ K)) %*% rmultinom(n = N, size = 1, prob = PIs)) # Defining matrix of possible attribute profiles As = rep(0, K) for (j in seq_len(K)) { temp = combn(1:K, m = j) tempmat = matrix(0, ncol(temp), K) for (j in seq_len(ncol(temp))) tempmat[j, temp[, j]] = 1 As = rbind(As, tempmat) } As = as.matrix(As) # Sample true attribute profiles Alphas = As[CLs, ] # Simulate item data under DINA model dina_items = sim_dina_items(Alphas, Q, ss, gs) # Simulate attribute data under DINA model dina_attributes = sim_dina_attributes(Alphas, Q)
MatrixCreates the ideal response matrix for each trait
sim_eta_matrix(K, J, Q)
sim_eta_matrix(K, J, Q)
K |
Number of Attribute Levels |
J |
Number of Assessment Items |
Q |
Q Matrix with dimensions |
A mat
with dimensions .
Steven Andrew Culpepper and James Joseph Balamuta
sim_q_matrix()
, attribute_bijection()
, and
attribute_inv_bijection()
## Simulation Settings ---- # Fixed Number of Assessment Items for Q J = 18 # Fixed Number of Attributes for Q K = 3 ## Pre-specified configuration ---- # Specify Q qbj = c(4, 2, 1, 4, 2, 1, 4, 2, 1, 6, 5, 3, 6, 5, 3, 7, 7, 7) # Fill Q Matrix Q = matrix(, J, K) for (j in seq_len(J)) { Q[j,] = attribute_inv_bijection(K, qbj[j]) } # Create an eta matrix ETA = sim_eta_matrix(K, J, Q) ## Random generation of Q matrix with ETA matrix ---- # Construct a random q matrix Q_sim = sim_q_matrix(J, K) # Generate the eta matrix ETA_gen = sim_eta_matrix(K, J, Q_sim)
## Simulation Settings ---- # Fixed Number of Assessment Items for Q J = 18 # Fixed Number of Attributes for Q K = 3 ## Pre-specified configuration ---- # Specify Q qbj = c(4, 2, 1, 4, 2, 1, 4, 2, 1, 6, 5, 3, 6, 5, 3, 7, 7, 7) # Fill Q Matrix Q = matrix(, J, K) for (j in seq_len(J)) { Q[j,] = attribute_inv_bijection(K, qbj[j]) } # Create an eta matrix ETA = sim_eta_matrix(K, J, Q) ## Random generation of Q matrix with ETA matrix ---- # Construct a random q matrix Q_sim = sim_q_matrix(J, K) # Generate the eta matrix ETA_gen = sim_eta_matrix(K, J, Q_sim)
Simulates a Q matrix containing three identity matrices after a row permutation that is identifiable.
sim_q_matrix(J, K)
sim_q_matrix(J, K)
J |
Number of Items |
K |
Number of Attributes |
A dichotomous matrix
for Q.
Steven Andrew Culpepper and James Joseph Balamuta
attribute_bijection()
and attribute_inv_bijection()
## Simulate identifiable Q matrices ---- # 7 items and 2 attributes q_matrix_j7_k2 = sim_q_matrix(7, 2) # 10 items and 3 attributes q_matrix_j10_k3 = sim_q_matrix(10, 3)
## Simulate identifiable Q matrices ---- # 7 items and 2 attributes q_matrix_j7_k2 = sim_q_matrix(7, 2) # 10 items and 3 attributes q_matrix_j10_k3 = sim_q_matrix(10, 3)
Randomly generate response data according to the reduced Reparameterized Unified Model (rRUM).
sim_rrum_items(Q, rstar, pistar, alpha)
sim_rrum_items(Q, rstar, pistar, alpha)
Q |
A |
rstar |
A |
pistar |
A |
alpha |
A |
Y A matrix
with rows and
columns indicating
the indviduals' responses to each of the items, where
represents the number of items.
Steven Andrew Culpepper, Aaron Hudson, and James Joseph Balamuta
Culpepper, S. A. & Hudson, A. (In Press). An improved strategy for Bayesian estimation of the reduced reparameterized unified model. Applied Psychological Measurement.
Hudson, A., Culpepper, S. A., & Douglas, J. (2016, July). Bayesian estimation of the generalized NIDA model with Gibbs sampling. Paper presented at the annual International Meeting of the Psychometric Society, Asheville, North Carolina.
# Set seed for reproducibility set.seed(217) # Define Simulation Parameters N = 1000 # number of individuals J = 6 # number of items K = 2 # number of attributes # Matrix where rows represent attribute classes As = attribute_classes(K) # Latent Class probabilities pis = c(.1, .2, .3, .4) # Q Matrix Q = rbind(c(1, 0), c(0, 1), c(1, 0), c(0, 1), c(1, 1), c(1, 1) ) # The probabiliies of answering each item correctly for individuals # who do not lack any required attribute pistar = rep(.9, J) # Penalties for failing to have each of the required attributes rstar = .5 * Q # Randomized alpha profiles alpha = As[sample(1:(K ^ 2), N, replace = TRUE, pis),] # Simulate data rrum_items = sim_rrum_items(Q, rstar, pistar, alpha)
# Set seed for reproducibility set.seed(217) # Define Simulation Parameters N = 1000 # number of individuals J = 6 # number of items K = 2 # number of attributes # Matrix where rows represent attribute classes As = attribute_classes(K) # Latent Class probabilities pis = c(.1, .2, .3, .4) # Q Matrix Q = rbind(c(1, 0), c(0, 1), c(1, 0), c(0, 1), c(1, 1), c(1, 1) ) # The probabiliies of answering each item correctly for individuals # who do not lack any required attribute pistar = rep(.9, J) # Penalties for failing to have each of the required attributes rstar = .5 * Q # Randomized alpha profiles alpha = As[sample(1:(K ^ 2), N, replace = TRUE, pis),] # Simulate data rrum_items = sim_rrum_items(Q, rstar, pistar, alpha)
Generate a sample from the
attribute profile matrix for members of class
such that
' is 1 if members of class
possess skill
and zero otherwise.
sim_subject_attributes(N, K, probs = NULL)
sim_subject_attributes(N, K, probs = NULL)
N |
Number of Observations |
K |
Number of Skills |
probs |
A |
A by
matrix
of latent classes
corresponding to entry of
based upon
mastery and nonmastery of the
skills.
James Joseph Balamuta and Steven Andrew Culpepper
attribute_classes()
and attribute_inv_bijection()
# Define number of subjects and attributes N = 100 K = 3 # Generate a sample from the Latent Attribute Profile (Alpha) Matrix # By default, we sample from a uniform distribution weighting of classes. alphas_builtin = sim_subject_attributes(N, K) # Generate a sample using custom probabilities from the # Latent Attribute Profile (Alpha) Matrix probs = rep(1 / (2 ^ K), 2 ^ K) alphas_custom = sim_subject_attributes(N, K, probs)
# Define number of subjects and attributes N = 100 K = 3 # Generate a sample from the Latent Attribute Profile (Alpha) Matrix # By default, we sample from a uniform distribution weighting of classes. alphas_builtin = sim_subject_attributes(N, K) # Generate a sample using custom probabilities from the # Latent Attribute Profile (Alpha) Matrix probs = rep(1 / (2 ^ K), 2 ^ K) alphas_custom = sim_subject_attributes(N, K, probs)