Learn R Programming

dcmstan (version 0.1.0)

stan_data: Create a list of data objects for 'Stan'

Description

When using 'Stan' to estimate a model, data objects must be passed as a list, where the name each object corresponds to the name of a variable in the data block of the 'Stan' code. stan_data() creates the list of data objects needed to estimate the model, consistent with the data block generated by stan_code().

Usage

stan_data(x, ...)

Value

A list of data objects.

Arguments

x

An object (e.g., a model specification) to create a data list for.

...

Additional arguments passed to methods. See details.

Details

Arguments for model specification method:

  • data: The response data. A data frame with 1 row per respondent and 1 column per item. May optionally include an additional column of item identifiers. If an identifier is included, this should be specified with identifier. All cells for the remaining item columns should be either 0 (incorrect response) or 1 (correct response).

  • missing: An expression specifying how missing values in data are encoded (e.g., NA, ".", -99). The default is NA.

  • identifier: Optional. If present, the quoted name of the column in data that contains respondent identifiers.

Arguments for generated quantities method:

  • dcm_spec: A cleaned data object, as returned by rdcmchecks::clean_data().

  • data: The response data. A data frame with 1 row per respondent and 1 column per item. May optionally include an additional column of item identifiers. If an identifier is included, this should be specified with identifier. All cells for the remaining item columns should be either 0 (incorrect response) or 1 (correct response).

  • missing: An expression specifying how missing values in data are encoded (e.g., NA, ".", -99). The default is NA.

  • identifier: Optional. If present, the quoted name of the column in data that contains respondent identifiers.

Examples

Run this code
qmatrix <- data.frame(
  att1 = sample(0:1, size = 5, replace = TRUE),
  att2 = sample(0:1, size = 5, replace = TRUE)
)
data <- data.frame(
  item_1 = sample(0:1, size = 20, replace = TRUE),
  item_2 = sample(0:1, size = 20, replace = TRUE),
  item_3 = sample(0:1, size = 20, replace = TRUE),
  item_4 = sample(0:1, size = 20, replace = TRUE),
  item_5 = sample(0:1, size = 20, replace = TRUE)
)

model_spec <- dcm_specify(qmatrix = qmatrix,
                          measurement_model = lcdm(),
                          structural_model = unconstrained())

stan_data(model_spec, data = data)

Run the code above in your browser using DataLab