irt_data {edstan} | R Documentation |
Create a Stan data list from an item response matrix or from long-form data.
Description
Create a Stan data list from an item response matrix or from long-form data.
Usage
irt_data(response_matrix = matrix(), y = integer(), ii = integer(),
jj = integer(), covariates = data.frame(), formula = ~1)
Arguments
response_matrix |
An item response matrix.
Columns represent items and rows represent persons.
NA may be supplied for missing responses.
The lowest score for each item should be 0, with exception to rating scale
models.
|
y |
A vector of scored responses for long-form data.
The lowest score for each item should be 0, with exception to rating scale
models.
NAs are not permitted, but missing responses may simply be ommitted
instead.
Required if |
ii |
A vector indexing the items in |
jj |
A vector indexing the persons in |
covariates |
An optional data frame containing (only) person-covariates.
It must contain one row per person or be of the same length as |
formula |
An optional formula for the latent regression that is applied
to |
Value
A data list suitable for irt_stan
.
See Also
See labelled_integer
for a means of creating
appropriate inputs for ii
and jj
.
See irt_stan
to fit a model to the data list.
Examples
# For a response matrix ("wide-form" data) with person covariates:
spelling_list <- irt_data(response_matrix = spelling[, 2:5],
covariates = spelling[, "male", drop = FALSE],
formula = ~ 1 + male)
# Alternatively, the same may be created by:
W <- cbind(intercept = 1, spelling[, "male"])
spelling_list <- irt_data(response_matrix = spelling[, 2:5],
covariates = W,
formula = NULL)
# For long-form data (one row per item-person pair):
agg_list_1 <- irt_data(y = aggression$poly,
ii = aggression$item,
jj = aggression$person)
# Add a latent regression and use labelled_integer() with the items
agg_list_2 <- irt_data(y = aggression$poly,
ii = labelled_integer(aggression$description),
jj = aggression$person,
covariates = aggression[, c("male", "anger")],
formula = ~ 1 + male*anger)