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()
uses the model specification
and a data frame of response data to create the list of data objects needed
to estimate the model, consistent with the data
block generated by
stan_code()
.
Arguments
- dcm_spec
A model specification object.
- 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 isNA
.- identifier
Optional. If present, the quoted name of the column in
data
that 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] 0 1 0 0 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 1
#> [35] 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0
#> [69] 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 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
#>