irtc_score: Score Raw Responses with an Answer Key or Scoring Rules

View source: R/irtc_score.R

irtc_scoreR Documentation

Score Raw Responses with an Answer Key or Scoring Rules

Description

Converts raw multiple-choice responses (e.g. "A", "B", "C", "D") to 0/1 scores using an answer key, or maps responses to partial-credit scores through a rules table. Responses are normalised before matching: whitespace is trimmed, case is ignored and full-width characters are converted to half-width.

Both key and rules may also be file paths in any format supported by irtc_read. A key file needs an item column (item, \zh题目\u9898\u76ee, ...) and an answer column (answer, \zh答案\u7b54\u6848, ...); an optional partial-answer column (partial_answer, \zh部分正确答案\u90e8\u5206\u6b63\u786e\u7b54\u6848, ...) lists answers worth partial credit, several separated by |, ;, , or \zh、\u3001. Items with partial answers are scored full = 2, partial = 1, other = 0; items without stay 0/1. For more than three score levels supply an explicit rules table instead.

Usage

irtc_score(resp, key = NULL, rules = NULL, na_as_wrong = FALSE,
    sheet = 1)

Arguments

resp

An irtc_data object (from irtc_read), a data frame or a matrix of raw responses.

key

A named vector mapping item names to correct answers, e.g. c(Q1 = "A", Q2 = "C"), or a path to a key file (see Description). An unnamed vector is matched to the item columns by position. Items not named in the key are left unchanged.

rules

A data frame with columns item, response, score defining partial-credit scoring, or a path to such a table (Chinese column aliases \zh题目\u9898\u76ee, \zh作答\u4f5c\u7b54 and \zh分值\u5206\u503c are accepted). Observed responses without a rule are set to NA with a warning of class irtc_warning_scoring.

na_as_wrong

Logical: score missing responses as 0 instead of NA? (Key scoring only.)

sheet

Excel sheet of the key / rules file (number or name).

Value

The same type as the input: an irtc_data object with scored resp and an extended log, or a data frame with a "scoring_log" attribute.

See Also

irtc_read, irtc

Examples

resp <- data.frame(Q1 = c("A", "b", "C"), Q2 = c("c", "C", "D"),
    stringsAsFactors = FALSE)
irtc_score(resp, key = c(Q1 = "A", Q2 = "C"))

rules <- data.frame(item = "Q1", response = c("A", "B", "C"),
    score = c(2, 1, 0))
irtc_score(resp["Q1"], rules = rules)

IRTC documentation built on July 24, 2026, 5:07 p.m.