Exercise: Build an exclusion ledger you can defend#

A small trial extract contains a duplicated record, impossible values, and a missing response. Separate corrections justified by the data contract from discretionary exclusion decisions.

See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.

# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
raw <- simulate_trials(seed=106, n_subjects=20, n_items=20)
raw$rt[c(2, 3, 4, 5)] <- c(-100, NA, 0, 5000)
raw <- rbind(raw, raw[1, ])

1. Triage without destroying evidence#

Identify duplicate trial IDs, nonpositive RTs, missing RTs, and the unusually slow value. Preserve raw and create explicit flags. Explain which issues violate measurement definitions and which require a substantive rule; do not assume every extreme observation is erroneous.

# Create an audit table with trial ID, raw value, and separate reason flags.

Your explanation and evidence:

2. Apply rules with accountable counts#

Remove the duplicated copy, missing RTs, and nonpositive RTs using a documented order. Produce a ledger with rows entering, newly excluded, and remaining at each step. Ensure overlapping flags cannot inflate the exclusion total. Check that the total reconciles with the final row count.

# Produce the cleaned table and reconciliation checks.

Your explanation and evidence:

3. Measure sensitivity to a discretionary choice#

Compare retaining all otherwise-valid RTs with restricting them to 150–1500 ms. For each, report trial and participant counts, mean, and median RT. Plot retained and excluded values. Explain why neither a nicer histogram nor a smaller p-value justifies choosing a rule retrospectively.

# Calculate the two-policy comparison and display the affected observations.

Your explanation and evidence:

What to submit#

An untouched raw object, flags, a reconciled exclusion ledger, and a two-policy sensitivity report. State what source information you would seek before treating 5000 ms as an error.