bidsaid.events.EPrimeBlockExtractor.extract_mean_accuracies
- EPrimeBlockExtractor.extract_mean_accuracies(subject_response_column, correct_response_column, valid_correct_responses=None, response_trial_names=None, response_required_only=False)[source]
Extract mean accuracy for each block.
Computes accuracy by comparing the subject’s response to the correct response for each trial.
Parameters
- subject_response_column
str The name of the column containing the subject’s response. Usually the column name ending in “.RESP”.
- correct_response_column
str The name of the column containing the correct response. Trials where the subject should not respond should be NaN. Usually column name ending in “.CRESP”.
- valid_correct_responses
Iterable[str | int | float]orNone, default=None Specific values in the
correct_response_columnto include in the computation. If provided, only trials where the correct response matches one of these values will be evaluated. This is useful for fixing the denominator to specific target trials (e.g., passing [“1”] to evaluate only Hit Rate, ignoring commission errors on NoGo trials that E-Prime might have encoded as “0”). If None, all non-NaN values are evaluated.- response_trial_names
Iterable[str]orNone, default=None The stimulus trial names within each block to include for the accuracy computation.
Important
If
split_cue_from_blockis True, trial types are excluded from this parameter.- response_required_only
bool, default=False Compute mean accuracy only for trials that expect a subject response. When True, the script assumes that trials not requiring a response (e.g., NoGo trials) are encoded as NaN in the
correct_response_column, and excludes them from the computation. This prevents overall accuracy scores from being artificially inflated by correct withholds. Set to False to include all trials regardless of whether a response was expected.Important
This parameter relies strictly on the presence of a non-NaN value in the
correct_response_columnto determine if a trial expects a response. If the log file explicitly assigns a value (e.g., “0”) to a trial that should not be responded to, the script will treat it as a valid, response-required trial and include it in the accuracy computation. Ensure withhold/NoGo trials are represented as NaN.
Returns
- list[float]
A list of mean accuracies for each block.
Notes
Correctness is determined by comparing
subject_response_columntocorrect_response_columnusing the following logic:Subject Response
Correct Response
Interpretation
Accuracy
“1”
“1”
Correct response
1
NaN
NaN
Correct response
1
NaN
“1”
Incorrect response
0
“1”
NaN
Incorrect response
0
“2”
“3”
Incorrect response
0
Note: If
response_required_onlyis True, only accuracy for the first, third, and fifth row are computed since those are trials that expect a response.Also, if cue is split from the block, NaN will be assigned for its accuracy.
Example
>>> # Get mean accuracy for all trial types >>> mean_accuracies = extractor.extract_mean_accuracies( ... subject_response_column="Stimulus.RESP", ... correct_response_column="CorrectResponse" ... ) >>> # Get mean accuracy for specific trial types only >>> mean_accuracies = extractor.extract_mean_accuracies( ... subject_response_column="Stimulus.RESP", ... correct_response_column="CorrectResponse", ... response_trial_names=("Go", "NoGo") ... )
Note
Mean accuracy for cue rows will be NaN.
- subject_response_column