Skip to contents

Something...

Usage

measr_dcm(
  data,
  missing = NA,
  qmatrix,
  resp_id = NULL,
  item_id = NULL,
  type = c("lcdm", "dina", "dino"),
  method = c("mcmc", "optim"),
  prior = NULL,
  backend = getOption("measr.backend", "rstan"),
  return_stanfit = TRUE,
  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 R expression specifying how missing data in data is coded (e.g., NA, ".", -99, etc.). The default is NA.

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

item_id

Optional. Variable name of a column in qmatrix that contains item identifiers. NULL (the default) indicates that no identifiers are present in the Q-matrix. In this case, the column names of data (excluding any column specified in resp_id) will be used as the item identifiers. NULL also assumes that the order of the rows in the Q-matrix is the same as the order of the columns in data (i.e., the item in row 1 of qmatrix is the item in column 1 of data, excluding resp_id).

type

Type of DCM to estimate. Must be one of lcdm, dina, or dino)`.

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 by default_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 current R session via the "measr.backend" option (see options()). Details on the rstan and cmdstanr packages are available at https://mc-stan.org/rstan/ and https://mc-stan.org/cmdstanr/, respectively.

return_stanfit

Logical. If backend = "cmdstanr", should the fitted model be coerced to a rstan::stanfit object in the . Ignored if backend = "rstan".

file

Either NULL (the default) or a character string. If a character string, the fitted model object is saved as an .rds object using saveRDS() using the supplied character string. The .rds extension is automatically added. If the specified file already exists, measr will load the previously saved model. Unless file_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 current R session via the "measr.file_refit" option (see options()).

  • For "never" (the default), the fitted model is always loaded if the file exists, and model fitting is skipped.

  • For "always", the model is always refitted, regardless of whether or not file exists.

  • For "on_change", the model will be refit if the data, prior, or method specified are different from that in the saved file.

...

Additional arguments passed to Stan.

Value

A measrfit object.