Skip to content

fix(metad): infer responses from accuracy in count_trials - #108

Merged
lenarddome merged 4 commits into
mainfrom
106-count_trials-doesnt-infer-responses-from-accuracy
Nov 11, 2026
Merged

lenarddome merged 4 commits into
mainfrom
106-count_trials-doesnt-infer-responses-from-accuracy

Conversation

@lenarddome

@lenarddome lenarddome commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #106.

Changes

  • count_trials ignored accuracy. When the responses column was missing, count_trials returned all-zero counts without an error, even though the docstring says it infers responses from accuracy.
    • Cause: the accuracy column was read but never used. responses stayed the column-name string "Responses", the loop went through its characters, and every trial was filtered out.
    • Fix: with accuracy only, responses are now worked out from it: a correct response is the stimulus, an incorrect one is the other stimulus.
  • Responses and accuracy are now checked against each other. When both are given, a trial where they disagree raises a ValueError giving the number of trials and their positions. EstimatorMetaD adds the participant to the error.
  • Arrays work without a DataFrame. data defaulted to the pd.DataFrame class instead of None, so passing arrays always raised.
  • No more silent all-zero counts. count_trials now:
    • raises an error when neither responses nor accuracy is given, when inputs have different lengths, or when no valid trials are left;
    • drops trials whose accuracy is not 0/1 or whose confidence is not a whole number;
    • warns when it drops stimuli not coded 0/1, for example 1/2 coding.
  • Docstring: fixed the example, which used an undefined data, the padding default and typos, and added a Raises section.
  • CHANGELOG: added entries under [Unreleased].

Compatibility

  • Responses-only input gives the same counts as before. This was checked against the old code on 3,000 random inputs and on load_metacognition_data(), and that dataset has no trials where responses and accuracy disagree.
  • Inconsistent data used to fit and now raises. Data with responses and accuracy that disagree used to fit without complaint; it now raises.
  • One test fixture value changed. synthetic_data in test/applications/test_signal_detection.py had a row with signal=1, response=1, accuracy=0, which the new check rejects, so that accuracy is now 1. The regression pickle is unchanged and still matches.

Tests

  • New tests: test/utils/test_metad.py has 18 tests, and test_signal_detection.py adds one for the participant name in the error.
  • Full suite: 790 passed.

Release

  • Bumps the version to 0.26.1 (cpm/__version__.py) and dates its CHANGELOG section. After merging, tag 0.26.1.
  • python -m build and twine check pass for the sdist and wheel.

🤖 Generated with Claude Code

lenarddome and others added 3 commits November 11, 2026 10:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e, name participant (#106)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lenarddome lenarddome linked an issue Nov 11, 2026 that may be closed by this pull request
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lenarddome
lenarddome merged commit bee9932 into main Nov 11, 2026
16 checks passed
@lenarddome
lenarddome deleted the 106-count_trials-doesnt-infer-responses-from-accuracy branch November 11, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

count_trials doesn't infer responses from accuracy

1 participant