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).
Arguments
- dcm_spec
A DCM specification created with
dcm_specify()
.- data
Response data. A data frame with 1 row per respondent and 1 column per item.
- missing
An
R
expression specifying how missing data indata
is coded (e.g.,NA
,"."
,-99
, etc.). The default isNA
.- identifier
Optional. Variable name of a column in
data
that contains respondent identifiers.NULL
(the default) indicates that no identifiers are present in the data, and row numbers will be used as identifiers.- method
Estimation method. Options are
"mcmc"
, which uses Stan's sampling method, or"optim"
, which uses Stan's optimizer.- 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 currentR
session 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.rds
object usingsaveRDS()
using the supplied character string. The.rds
extension is automatically added. If the specified file already exists, measr will load the previously saved model. Unlessfile_refit
is 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 currentR
session via the "measr.file_refit" option (seeoptions()
).For
"never"
(the default), the fitted model is always loaded if thefile
exists, and model fitting is skipped.For
"always"
, the model is always refitted, regardless of whether or notfile
exists.For
"on_change"
, the model will be refit if thedcm_spec
,data
,method
, orbackend
specified 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.
Examples
model_spec <- dcm_specify(qmatrix = dcmdata::mdm_qmatrix,
identifier = "item")
model <- dcm_estimate(dcm_spec = model_spec, data = dcmdata::mdm_data,
identifier = "respondent", method = "optim",
seed = 63277)