Estimate diagnostic classification models (DCMs; also known as cognitive diagnostic models) using 'Stan'. Models can be estimated using Stan's optimizer, or full Markov chain Monte Carlo (MCMC).
Usage
measr_dcm(
data,
missing = NA,
qmatrix,
resp_id = NULL,
item_id = NULL,
type = c("lcdm", "dina", "dino", "crum"),
max_interaction = Inf,
attribute_structure = c("unconstrained", "independent"),
method = c("mcmc", "optim"),
prior = NULL,
backend = getOption("measr.backend", "rstan"),
file = NULL,
file_refit = getOption("measr.file_refit", "never"),
...
)Arguments
- data
Response data. A data frame with 1 row per respondent and 1 column per item.
- missing
An
Rexpression specifying how missing data indatais coded (e.g.,NA,".",-99, etc.). The default isNA.- qmatrix
The Q-matrix. A data frame with 1 row per item and 1 column per attribute. All cells should be either 0 (item does not measure the attribute) or 1 (item does measure the attribute).
- resp_id
Optional. Variable name of a column in
datathat contains respondent identifiers.NULL(the default) indicates that no identifiers are present in the data, and row numbers will be used as identifiers.- item_id
Optional. Variable name of a column in
qmatrixthat contains item identifiers.NULL(the default) indicates that no identifiers are present in the Q-matrix. In this case, the column names ofdata(excluding any column specified inresp_id) will be used as the item identifiers.NULLalso assumes that the order of the rows in the Q-matrix is the same as the order of the columns indata(i.e., the item in row 1 ofqmatrixis the item in column 1 ofdata, excludingresp_id).- type
Type of DCM to estimate. Must be one of lcdm, dina, dino, or crum.
- max_interaction
If
type = "lcdm", the highest level of interaction to estimate. The default is to estimate all possible interactions. For example, an item that measures 4 attributes would have 4 main effects, 6 two-way interactions, 4 three-way interactions, and 1 four-way interaction. Settingmax_interaction = 2would result in only estimating the main effects and two-way interactions, excluding the three- and four- way interactions.- attribute_structure
Structural model specification. Must be one of unconstrained, or independent.
unconstrainedmakes no assumptions about the relationships between attributes, whereasindependentassumes that proficiency statuses on attributes are independent of each other.- method
Estimation method. Options are
"mcmc", which uses Stan's sampling method, or"optim", which uses Stan's optimizer.- prior
A measrprior object. If
NULL, default priors are used, as specified bydefault_dcm_priors().- backend
Character string naming the package to use as the backend for fitting the Stan model. Options are
"rstan"(the default) or"cmdstanr". Can be set globally for the currentRsession via the "measr.backend" option (seeoptions()). Details on the rstan and cmdstanr packages are available at https://mc-stan.org/rstan/ and https://mc-stan.org/cmdstanr/, respectively.- file
Either
NULL(the default) or a character string. If a character string, the fitted model object is saved as an.rdsobject usingsaveRDS()using the supplied character string. The.rdsextension is automatically added. If the specified file already exists, measr will load the previously saved model. Unlessfile_refitis specified, the model will not be refit.- file_refit
Controls when a saved model is refit. Options are
"never","always", and"on_change". Can be set globally for the currentRsession via the "measr.file_refit" option (seeoptions()).For
"never"(the default), the fitted model is always loaded if thefileexists, and model fitting is skipped.For
"always", the model is always refitted, regardless of whether or notfileexists.For
"on_change", the model will be refit if thedata,prior, ormethodspecified are different from that in the savedfile.
- ...
Additional arguments passed to Stan.
For
backend = "rstan", arguments are passed torstan::sampling()orrstan::optimizing().For
backend = "cmdstanr", arguments are passed to the sample or optimize methods of the CmdStanModel class.
Value
A measrfit object.
