irt_data: Create a Stan data list from an item response matrix or from...

Description Usage Arguments Value See Also Examples

View source: R/fitting_functions.R

Description

Create a Stan data list from an item response matrix or from long-form data.

Usage

1
2
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, ii, and jj should not be supplied if a response matrix is given.

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 response_matrix is not supplied.

ii

A vector indexing the items in y. This must consist of consecutive integers starting at 1. labelled_integer may be used to create a suitable vector. Required if response_matrix is not supplied.

jj

A vector indexing the persons in y. This must consist of consecutive integers starting at 1. labelled_integer may be used to create a suitable vector. Required if response_matrix is not supplied.

covariates

An optional data frame containing (only) person-covariates. It must contain one row per person or be of the same length as y, ii, and jj. If it contains one row per person, it must be in the same order as the response matrix (or unique(jj)). If it has a number of columns equal to the length of y, ii, and jj, it must be in the same order as jj (for example, it may be a subset of columns from the same data frame that contains y, ii, and jj).

formula

An optional formula for the latent regression that is applied to covariates. The left side should be blank (for example, ~ v1 + v2). By default it includes only a model intercept, interpretable as the mean of the person distribution. If set to NULL, then covariates is used directly as the design matrix for the latent regression.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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)

Example output

Loading required package: rstan
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Warning message:
In file(con, "r") : cannot open file '/proc/stat': Permission denied

edstan documentation built on May 2, 2019, 4:18 a.m.