Package 'simcdm'

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-24 06:39:51 UTC
Source: CRAN

Help Index


simcdm: 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.

Author(s)

Maintainer: James Joseph Balamuta [email protected] (ORCID) [copyright holder]

Authors:

Other contributors:

See Also

Useful links:


Constructs Unique Attribute Pattern Map

Description

Computes the powers of 2 from 00 up to K1K - 1 for KK-dimensional attribute pattern.

Usage

attribute_bijection(K)

Arguments

K

Number of Attributes.

Value

A vec with length KK detailing the power's of 2.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

attribute_inv_bijection()

Examples

## Construct an attribute bijection ----
biject = attribute_bijection(3)

Simulate all the Latent Attribute Profile αc\mathbf{\alpha}_c in Matrix form

Description

Generate the αc=(αc1,,αcK)\mathbf{\alpha}_c = (\alpha_{c1}, \ldots, \alpha_{cK})' attribute profile matrix for members of class cc such that αck\alpha_{ck} ' is 1 if members of class cc possess skill kk and zero otherwise.

Usage

attribute_classes(K)

Arguments

K

Number of Attributes

Value

A 2K2^K by KK matrix of latent classes corresponding to entry cc of pipi based upon mastery and nonmastery of the KK skills.

Author(s)

James Joseph Balamuta and Steven Andrew Culpepper

See Also

sim_subject_attributes() and attribute_inv_bijection()

Examples

## Simulate Attribute Class Matrix ----

# Define number of attributes
K = 3

# Generate an Latent Attribute Profile (Alpha) Matrix
alphas = attribute_classes(K)

Perform an Inverse Bijection of an Integer to Attribute Pattern

Description

Convert an integer between 00 and 2K12^{K-1} to KK-dimensional attribute pattern.

Usage

attribute_inv_bijection(K, CL)

Arguments

K

Number of Attributes.

CL

An integer between 00 and 2K12^{K-1}

Value

A KK-dimensional vector with an attribute pattern corresponding to CL.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

attribute_bijection()

Examples

## Construct an attribute inversion bijection ----
inv_biject1 = attribute_inv_bijection(5, 1)
inv_biject2 = attribute_inv_bijection(5, 2)

Simulate a DINA Model's η\eta Matrix

Description

Generates a DINA model's η\eta matrix based on alphas and the Q\mathbf{Q} matrix.

Usage

sim_dina_attributes(alphas, Q)

Arguments

alphas

A NN by KK matrix of latent attributes.

Q

A JJ by KK matrix indicating which skills are required for which items.

Value

The η\eta matrix with dimensions N×JN \times J under the DINA model.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

sim_dina_class() and sim_dina_items()

Examples

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)

Simulate Binary Responses for a DINA Model

Description

Generate the dichotomous item matrix for a DINA Model.

Usage

sim_dina_class(N, J, CLASS, ETA, gs, ss)

Arguments

N

Number of Observations

J

Number of Assessment Items

CLASS

Does the individual possess all the necessary attributes?

ETA

η\eta Matrix containing indicators.

gs

A vec describing the probability of guessing or the probability subject correctly answers item jj when at least one attribute is lacking.

ss

A vec describing the probability of slipping or the probability of an incorrect response for individuals with all of the required attributes

Value

A dichotomous item matrix with dimensions N×JN \times J.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

sim_dina_attributes() and sim_dina_items()

Examples

# 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)

Simulation Responses from the DINA model

Description

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.

Usage

sim_dina_items(alphas, Q, ss, gs)

Arguments

alphas

A NN by KK matrix of latent attributes.

Q

A JJ by KK matrix indicating which skills are required for which items.

ss

A JJ vector of item slipping parameters.

gs

A JJ vector of item guessing parameters.

Value

A NN by JJ matrix of responses from the DINA model.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

sim_dina_class() and sim_dina_attributes()

Examples

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 ideal response η\eta Matrix

Description

Creates the ideal response matrix for each trait

Usage

sim_eta_matrix(K, J, Q)

Arguments

K

Number of Attribute Levels

J

Number of Assessment Items

Q

Q Matrix with dimensions K×JK \times J.

Value

A mat with dimensions J×2KJ \times 2^K.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

sim_q_matrix(), attribute_bijection(), and attribute_inv_bijection()

Examples

## 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)

Generate a Random Identifiable Q Matrix

Description

Simulates a Q matrix containing three identity matrices after a row permutation that is identifiable.

Usage

sim_q_matrix(J, K)

Arguments

J

Number of Items

K

Number of Attributes

Value

A dichotomous matrix for Q.

Author(s)

Steven Andrew Culpepper and James Joseph Balamuta

See Also

attribute_bijection() and attribute_inv_bijection()

Examples

## 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)

Generate data from the rRUM

Description

Randomly generate response data according to the reduced Reparameterized Unified Model (rRUM).

Usage

sim_rrum_items(Q, rstar, pistar, alpha)

Arguments

Q

A matrix with JJ rows and KK columns indicating which attributes are required to answer each of the items, where JJ represents the number of items and KK the number of attributes. An entry of 1 indicates attribute kk is required to answer item jj. An entry of one indicates attribute kk is not required.

rstar

A matrix a matrix with JJ rows and KK columns indicating the penalties for failing to have each of the required attributes, where JJ represents the number of items and KK the number of attributes. rstar and Q must share the same 0 entries.

pistar

A vector of length JJ indicating the probabiliies of answering each item correctly for individuals who do not lack any required attribute, where JJ represents the number of items.

alpha

A matrix with NN rows and KK columns indicating the subjects attribute acquisition, where KK represents the number of attributes. An entry of 1 indicates individual ii has attained attribute kk. An entry of 0 indicates the attribute has not been attained.

Value

Y A matrix with NN rows and JJ columns indicating the indviduals' responses to each of the items, where JJ represents the number of items.

Author(s)

Steven Andrew Culpepper, Aaron Hudson, and James Joseph Balamuta

References

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.

Examples

# 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)

Simulate Subject Latent Attribute Profiles αc\mathbf{\alpha}_c

Description

Generate a sample from the αc=(αc1,,αcK)\mathbf{\alpha}_c = (\alpha_{c1}, \ldots, \alpha_{cK})' attribute profile matrix for members of class cc such that αck\alpha_{ck} ' is 1 if members of class cc possess skill kk and zero otherwise.

Usage

sim_subject_attributes(N, K, probs = NULL)

Arguments

N

Number of Observations

K

Number of Skills

probs

A vector of probabilities that sum to 1.

Value

A NN by KK matrix of latent classes corresponding to entry cc of pipi based upon mastery and nonmastery of the KK skills.

Author(s)

James Joseph Balamuta and Steven Andrew Culpepper

See Also

attribute_classes() and attribute_inv_bijection()

Examples

# 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)