Learn R Programming

DCC (version 1.2.1)

dcc_score: Score responses against an answer key

Description

Scores responses using an external, versioned answer key. Single-choice items get full points on exact match. Multiple-select items (responses like "AC" or "A,C") are all-or-nothing by default; with partial = TRUE the score is points * max(0, (hits - false_alarms) / n_key). When omit_policy = "na", a row with no observed item scores has an NA total rather than zero.

Usage

dcc_score(x, answer_key, omit_policy = c("zero", "na"),
  scoring_fn = NULL)

Value

A new dcc_data version with one <item>_score

column per keyed item and a total_score column appended, plus a score provenance record (key source, key hash, omit policy).

Arguments

x

A dcc_data object or data.frame of responses.

answer_key

A data.frame with columns item, key, and optionally type ("single"/"multiple", default "single"), points (default 1), partial (default FALSE) -- or a path to a CSV file with those columns (the file's MD5 hash is recorded in the provenance chain).

omit_policy

"zero" (omitted item scores 0, default) or "na" (omitted stays NA; use after dcc_map_forms so not-administered items are not scored as wrong).

scoring_fn

Optional function(responses, key_row) returning a numeric vector with exactly one value per response; replaces built-in scoring for every item. This is the extension point reserved for weighted/rubric/polytomous scoring (design decision 2).

Examples

Run this code
df <- data.frame(sid = c("S1", "S2"),
                 it1 = c("A", "B"), it2 = c("AC", "A"))
key <- data.frame(item = c("it1", "it2"), key = c("A", "AC"),
                  type = c("single", "multiple"))
as.data.frame(dcc_score(df, key))

Run the code above in your browser using DataLab