Learn R Programming

LCPA (version 1.0.0)

adjust.response: Adjust Categorical Response Data for Polytomous Items

Description

Standardizes polytomous response data by converting raw category values to consecutive integers starting from 0. Records original category values for potential reverse transformation. Handles varying numbers of response categories across items.

Usage

adjust.response(response)

Value

A named list containing:

poly.orig

\(I \times K_{max}\) matrix. Original sorted category values for each item. Rows correspond to items, columns to category positions. Empty cells filled with NA.

poly.value

Integer vector of length \(I\). Number of unique response categories per item.

poly.max

Scalar integer. Maximum number of categories across all items, i.e., \(K_{max}\).

response

\(N \times I\) matrix. Adjusted response data where original values are replaced by zero-based category indices (0 to \(k-1\) for \(k\) categories).

Arguments

response

A matrix or data frame containing response data where:

  • Rows represent respondents (\(N\) observations)

  • Columns represent items/questions (\(I\) items)

  • Cells contain raw response values (numeric)

Non-numeric columns will be coerced to numeric with warning.

Details

The function processes each item column independently:

  1. Extracts unique response values and sorts them in ascending order

  2. Maps smallest value to 0, second smallest to 1, etc.

  3. Records original values in poly.orig for possible reverse transformation

  4. Handles items with different numbers of categories through NA-padding

Missing values (NA) in input are preserved as NA in output.

Examples

Run this code
# Simulate response data with 3 items and varying categories
set.seed(123)
resp <- data.frame(
  item1 = sample(1:3, 10, replace = TRUE),
  item2 = sample(c(0, 5, 10), 10, replace = TRUE),
  item3 = sample(1:2, 10, replace = TRUE)
)

# Apply adjustment
adjusted <- adjust.response(resp)

# Inspect results
str(adjusted)
print(adjusted$poly.orig)  # Original category values
print(adjusted$response)   # Standardized responses

Run the code above in your browser using DataLab