Skip to contents

This function prepares the data with polytomous item responses for explanatory item response modeling. If the data is already in a long format (i.e., items by person), it only recodes the polytomous responses and creates a new variable to be used for the estimation. If the data is not in the long format, then both reshaping the data into the long format and recoding items can be done simultaneously.

Usage

polyreformat(
  data,
  id.var,
  long.format = FALSE,
  var.name = "item",
  val.name = "resp"
)

Arguments

data

A data frame -- either in a wide format where the rows represent persons and columns represent items explanatory variables or in a long format where there are multiple rows for each person (i.e., nested data)

id.var

The variable that represents examinee IDs.

long.format

Whether the data follow a wide format and thus need to be transformed into a long format first (default is FALSE)

var.name

The variable that represents item IDs if the data is already in long format; otherwise this is the of the variable that represents item IDs once the data is transformed into long format.

val.name

The variable that represents item responses if the data is already in long format; otherwise this is the of the variable that represents item responses once the data is transformed into long format.

Value

Reformatted data for explanatory item response modeling.

Examples

data("VerbAgg")
VerbAgg2 <- polyreformat(data=VerbAgg, id.var = "id", long.format = FALSE,
var.name = "item", val.name = "resp")
head(VerbAgg2)
#>   Anger Gender        item    resp id btype  situ mode r2 polycategory
#> 1    20      M S1WantCurse      no  1 curse other want  N  cat_perhaps
#> 2    11      M S1WantCurse      no  2 curse other want  N  cat_perhaps
#> 3    17      F S1WantCurse perhaps  3 curse other want  Y  cat_perhaps
#> 4    21      F S1WantCurse perhaps  4 curse other want  Y  cat_perhaps
#> 5    17      F S1WantCurse perhaps  5 curse other want  Y  cat_perhaps
#> 6    21      F S1WantCurse     yes  6 curse other want  Y  cat_perhaps
#>   polyresponse                polyitem
#> 1            0 S1WantCurse.cat_perhaps
#> 2            0 S1WantCurse.cat_perhaps
#> 3            1 S1WantCurse.cat_perhaps
#> 4            1 S1WantCurse.cat_perhaps
#> 5            1 S1WantCurse.cat_perhaps
#> 6           NA S1WantCurse.cat_perhaps