sim.gdina {CDM} | R Documentation |
Simulation of the GDINA model
Description
The function sim.gdina.prepare
creates necessary design matrices
Mj
, Aj
and necc.attr
. In most cases, only the list
of item parameters delta
must be modified by the user when
applying the simulation function sim.gdina
. The distribution of latent
classes \alpha
is represented by an underlying multivariate normal distribution
\alpha^\ast
for which a mean vector thresh.alpha
and a
covariance matrix cov.alpha
must be specified.
Alternatively, a matrix of skill classes alpha
can be given as an input.
Note that this version of sim.gdina
only works for dichotomous attributes.
Usage
sim.gdina(n, q.matrix, delta, link="identity", thresh.alpha=NULL,
cov.alpha=NULL, alpha=NULL, Mj, Aj, necc.attr)
sim.gdina.prepare( q.matrix )
Arguments
n |
Number of persons |
q.matrix |
Q-matrix (see |
delta |
List with |
link |
Link function. Choices are |
thresh.alpha |
Vector of thresholds (means) of |
cov.alpha |
Covariance matrix of |
alpha |
Matrix of skill classes if they should not be simulated |
Mj |
Design matrix, see |
Aj |
Design matrix, see |
necc.attr |
List with |
Value
The output of sim.gdina
is a list with following entries:
data |
Simulated item responses |
alpha |
Data frame with simulated attributes |
q.matrix |
Used Q-matrix |
delta |
Used delta item parameters |
Aj |
Design matrices |
Mj |
Design matrices |
link |
Used link function |
The function sim.gdina.prepare
possesses the following values as output
in a list: delta
, necc.attr
, Aj
and Mj
.
References
de la Torre, J. (2011). The generalized DINA model framework. Psychometrika, 76, 179–199.
See Also
For estimating the GDINA model see gdina
.
See the GDINA::simGDINA
function in the
GDINA package for similar functionality.
See sim_model
for a general simulation function.
Examples
#############################################################################
# EXAMPLE 1: Simulating the GDINA model
#############################################################################
n <- 50 # number of persons
# define Q-matrix
q.matrix <- matrix( c(1,1,0, 0,1,1, 1,0,1, 1,0,0,
0,0,1, 0,1,0, 1,1,1, 0,1,1, 0,1,1), ncol=3, byrow=TRUE)
# thresholds for attributes alpha^\ast
thresh.alpha <- c( .65, 0, -.30 )
# covariance matrix for alpha^\ast
cov.alpha <- matrix(1,3,3)
cov.alpha[1,2] <- cov.alpha[2,1] <- .4
cov.alpha[1,3] <- cov.alpha[3,1] <- .6
cov.alpha[3,2] <- cov.alpha[2,3] <- .8
# prepare design matrix by applying sim.gdina.prepare function
rp <- CDM::sim.gdina.prepare( q.matrix )
delta <- rp$delta
necc.attr <- rp$necc.attr
Aj <- rp$Aj
Mj <- rp$Mj
# define delta parameters
# intercept - main effects - second order interactions - ...
str(delta) #=> modify the delta parameter list which contains only zeroes as default
## List of 9
## $ : num [1:4] 0 0 0 0
## $ : num [1:4] 0 0 0 0
## $ : num [1:4] 0 0 0 0
## $ : num [1:2] 0 0
## $ : num [1:2] 0 0
## $ : num [1:2] 0 0
## $ : num [1:8] 0 0 0 0 0 0 0 0
## $ : num [1:4] 0 0 0 0
## $ : num [1:4] 0 0 0 0
delta[[1]] <- c( .2, .1, .15, .4 )
delta[[2]] <- c( .2, .3, .3, -.2 )
delta[[3]] <- c( .2, .2, .2, 0 )
delta[[4]] <- c( .15, .6 )
delta[[5]] <- c( .1, .7 )
delta[[6]] <- c( .25, .65 )
delta[[7]] <- c( .25, .1, .1, .1, 0, 0, 0, .25 )
delta[[8]] <- c( .2, 0, .3, -.1 )
delta[[9]] <- c( .2, .2, 0, .3 )
#******************************************
# Now, the "real simulation" starts
sim.res <- CDM::sim.gdina( n=n, q.matrix=q.matrix, delta=delta, link="identity",
thresh.alpha=thresh.alpha, cov.alpha=cov.alpha,
Mj=Mj, Aj=Aj, necc.attr=necc.attr)
# sim.res$data # simulated data
# sim.res$alpha # simulated alpha
## Not run:
#############################################################################
# EXAMPLE 2: Simulation based on already estimated GDINA model for data.ecpe
#############################################################################
data(data.ecpe)
dat <- data.ecpe$data
q.matrix <- data.ecpe$q.matrix
#***
# (1) estimate GDINA model
mod <- CDM::gdina( data=dat[,-1], q.matrix=q.matrix )
#***
# (2) simulate data according to GDINA model
set.seed(977)
# prepare design matrix by applying sim.gdina.prepare function
rp <- CDM::sim.gdina.prepare( q.matrix )
necc.attr <- rp$necc.attr
# number of subjects to be simulated
n <- 3000
# simulate attribute patterns
probs <- mod$attribute.patt$class.prob # probabilities
patt <- mod$attribute.patt.splitted # response patterns
alpha <- patt[ sample( 1:(length(probs) ), n, prob=probs, replace=TRUE), ]
# simulate data using estimated item parameters
sim.res <- CDM::sim.gdina( n=n, q.matrix=q.matrix, delta=mod$delta, link="identity",
alpha=alpha, Mj=mod$Mj, Aj=mod$Aj, necc.attr=rp$necc.attr)
# extract data
dat <- sim.res$data
#############################################################################
# EXAMPLE 3: Simulation based on already estimated RRUM model for data.ecpe
#############################################################################
dat <- CDM::data.ecpe$data
q.matrix <- CDM::data.ecpe$q.matrix
#***
# (1) estimate reduced RUM model
mod <- CDM::gdina( data=dat[,-1], q.matrix=q.matrix, rule="RRUM" )
summary(mod)
#***
# (2) simulate data according to RRUM model
set.seed(977)
# prepare design matrix by applying sim.gdina.prepare function
rp <- CDM::sim.gdina.prepare( q.matrix )
necc.attr <- rp$necc.attr
# number of subjects to be simulated
n <- 5000
# simulate attribute patterns
probs <- mod$attribute.patt$class.prob # probabilities
patt <- mod$attribute.patt.splitted # response patterns
alpha <- patt[ sample( 1:(length(probs) ), n, prob=probs, replace=TRUE), ]
# simulate data using estimated item parameters
sim.res <- CDM::sim.gdina( n=n, q.matrix=q.matrix, delta=mod$delta, link=mod$link,
alpha=alpha, Mj=mod$Mj, Aj=mod$Aj, necc.attr=rp$necc.attr)
# extract data
dat <- sim.res$data
## End(Not run)