get.response.from.data: Convert FC Data Strings to an Integer Response...

View source: R/tools-data.R

get.response.from.dataR Documentation

Convert FC Data Strings to an Integer Response (Pattern-Index) Matrix

Description

Parses human-readable forced-choice data strings into integer pattern indices. This is the generic converter used by FCGGUM, FCMIRT, and FCGDINA. Each data cell is matched against the full set of permutation/observation patterns for that block, and the resulting row index is stored in the response matrix.

Usage

get.response.from.data(data, block.items, fc.type = "RANK")

Arguments

data

An N \times B character matrix or data frame. Cells encode within-block item orderings as global indices separated by ">" (e.g. "3>1>2" for RANK, "3>2" for MOLE, "3" for PICK).

block.items

A list of length B giving the global item indices in each forced-choice block.

fc.type

Character vector of length B (or a scalar recycled to all blocks): "RANK", "MOLE", or "PICK".

Value

An N \times B integer matrix. Each entry is a 1-based pattern index (row number in the block's pattern matrix). Column names are "block.1", ..., "block.B".

Pattern Matching

The conversion first generates all possible observation patterns for each block via the internal permutation helper:

  • RANK (K items): all K! full rankings, ordered lexicographically by within-block position.

  • MOLE: K(K-1) most-least observation patterns.

  • PICK: K best-only patterns.

Each data cell string is parsed into an integer vector of global item indices, which is then matched (as an ordered sequence) against the pattern matrix. The 1-based row index of the match becomes the response value. Pattern ordering is deterministic and reproducible.

A non-missing cell that cannot be matched to a valid pattern is returned as NA_integer_. This is useful for data-screening workflows: after conversion, check anyNA(response) before passing the response matrix to a fitting function.

See Also

get.data.from.response for the reverse conversion.

generate_fc_permutation_patterns for pattern generation details.

get.response.from.data.TIRT for the TIRT-specific converter.

Examples

# 2 persons, 2 RANK blocks.
items <- list(1:2, 3:5)
dat <- data.frame(
  block.1 = c("1>2", "2>1"),
  block.2 = c("3>4>5", "5>4>3"),
  stringsAsFactors = FALSE
)
resp <- get.response.from.data(dat, items, fc.type = "RANK")
resp
get.data.from.response(resp, items, fc.type = "RANK")

# Mixed block formats: most-least plus pick.
dat.mixed <- data.frame(
  mole = c("1>3", "3>2"),
  pick = c("4", "6"),
  stringsAsFactors = FALSE
)
mixed.items <- list(1:3, 4:6)
get.response.from.data(
  dat.mixed, mixed.items, fc.type = c("MOLE", "PICK")
)

ForceChoice documentation built on Sept. 13, 2026, 1:06 a.m.