Learn R Programming

LCPA (version 1.0.0)

check.response: Validate response matrix against expected polytomous category counts

Description

Checks whether each column in the response matrix contains exactly the number of unique response categories specified in poly.value. Handles edge cases where all items have identical category counts efficiently.

Usage

check.response(response, poly.value)

Value

Logical value indicating validation status:

  • TRUE if either:

    • All columns have identical numbers of unique values (regardless of poly.value specification)

    • Each column's unique value count matches its corresponding poly.value entry

  • FALSE if any column's unique value count mismatches its specified poly.value (when columns have varying category counts)

Arguments

response

A numeric matrix of dimension \(N \times I\), where:

  • \(N\): Number of subjects/observations (rows)

  • \(I\): Number of items/variables (columns)

Each cell contains the observed response value for a subject on an item.

poly.value

An integer vector of length \(I\) specifying the expected number of unique response categories (levels) for each corresponding item in response. Values must be positive integers.

Examples

Run this code
# Valid case: Matching category counts
resp_matrix <- matrix(c(1,1,2,2, 1,2,3,1), ncol = 2)
check.response(resp_matrix, poly.value = c(2, 3))  # Returns TRUE

# Invalid case: Mismatched category counts
check.response(resp_matrix, poly.value = c(2, 2))  # Returns FALSE

# Special case: Uniform category counts bypass poly.value check
uniform_resp <- matrix(rep(1:2, each = 4), ncol = 2)
check.response(uniform_resp, poly.value = c(2, 5))  # Returns TRUE (bypass behavior)

Run the code above in your browser using DataLab