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().
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 withidentifier. All cells for the remaining item columns should be either 0 (incorrect response) or 1 (correct response).missing: An expression specifying how missing values indataare encoded (e.g.,NA,".",-99). The default isNA.identifier: Optional. If present, the quoted name of the column indatathat contains respondent identifiers.
Arguments for generated quantities method:
dcm_spec: A cleaned data object, as returned byrdcmchecks::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 withidentifier. All cells for the remaining item columns should be either 0 (incorrect response) or 1 (correct response).missing: An expression specifying how missing values indataare encoded (e.g.,NA,".",-99). The default isNA.identifier: Optional. If present, the quoted name of the column indatathat contains respondent identifiers.
Examples
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)
#> $I
#> [1] 5
#>
#> $R
#> [1] 20
#>
#> $N
#> [1] 100
#>
#> $C
#> [1] 4
#>
#> $ii
#> [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4
#> [35] 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3
#> [69] 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
#>
#> $rr
#> [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5
#> [24] 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 10
#> [47] 10 10 10 10 11 11 11 11 11 12 12 12 12 12 13 13 13 13 13 14 14 14 14
#> [70] 14 15 15 15 15 15 16 16 16 16 16 17 17 17 17 17 18 18 18 18 18 19 19
#> [93] 19 19 19 20 20 20 20 20
#>
#> $y
#> [1] 1 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 0 0
#> [35] 1 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 1 1 0 1 1 0 1 1
#> [69] 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 1 0 1 0 0 1 1 1 1
#>
#> $start
#> [1] 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96
#>
#> $num
#> [1] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
#>