metadpy.utils.trials2counts#

metadpy.utils.trials2counts(data: None, stimuli: Union[list, ndarray], responses: Union[list, ndarray], accuracy: Union[list, ndarray], confidence: Union[list, ndarray], nRatings: int = 4, padding: bool = False, padAmount: Optional[float] = None) Tuple[ndarray, ndarray][source]#
metadpy.utils.trials2counts(data=pd.DataFrame, stimuli: str = 'Stimuli', responses: str = 'Responses', accuracy: str = 'Accuracy', confidence: str = 'Confidence', nRatings: int = 4, padding: bool = False, padAmount: Optional[float] = None) Tuple[ndarray, ndarray]

Convert raw behavioral data to nR_S1 and nR_S2 response count.

Given data from an experiment where an observer discriminates between two stimulus alternatives on every trial and provides confidence ratings, converts trial by trial experimental information for N trials into response counts.

Parameters
data

Dataframe containing stimuli, accuracy and confidence ratings.

stimuli

Stimuli ID (0 or 1). If a dataframe is provided, should be the name of the column containing the stimuli ID. Default is ‘Stimuli’.

responses

Response (0 or 1). If a dataframe is provided, should be the name of the column containing the response accuracy. Default is ‘Responses’.

accuracy

Response accuracy (0 or 1). If a dataframe is provided, should be the name of the column containing the response accuracy. Default is ‘Accuracy’.

confidence

Confidence ratings. If a dataframe is provided, should be the name of the column containing the confidence ratings. Default is ‘Confidence’.

nRatings

Total of available subjective ratings available for the subject. e.g. if subject can rate confidence on a scale of 1-4, then nRatings = 4. Default is 4.

padding

If True, each response count in the output has the value of padAmount added to it. Padding cells is desirable if trial counts of 0 interfere with model fitting. If False, trial counts are not manipulated and 0s may be present in the response count output. Default value for padding is 0.

padAmount

The value to add to each response count if padding is set to 1. Default value is 1/(2*nRatings)

Returns
nR_S1, nR_S2

Vectors containing the total number of responses in each accuracy category, conditional on presentation of S1 and S2.

Notes

All trials where stimuli is not 0 or 1, accuracy is not 0 or 1, or confidence is not in the range [1, nRatings], are automatically omitted.

The inputs can be responses, accuracy or both. If both responses and accuracy are provided, will check for consstency. If only accuracy is provided, the responses vector will be automatically infered.

If nR_S1 = [100 50 20 10 5 1], then when stimulus S1 was presented, the subject had the following accuracy counts:

responded S1, confidence=3 : 100 times responded S1, confidence=2 : 50 times responded S1, confidence=1 : 20 times responded S2, confidence=1 : 10 times responded S2, confidence=2 : 5 times responded S2, confidence=3 : 1 time

The ordering of accuracy / confidence counts for S2 should be the same as it is for S1. e.g. if nR_S2 = [3 7 8 12 27 89], then when stimulus S2 was presented, the subject had the following accuracy counts:

responded S1, confidence=3 : 3 times responded S1, confidence=2 : 7 times responded S1, confidence=1 : 8 times responded S2, confidence=1 : 12 times responded S2, confidence=2 : 27 times responded S2, confidence=3 : 89 times

Examples

>>> stimID = [0, 1, 0, 0, 1, 1, 1, 1]
>>> accuracy = [0, 1, 1, 1, 0, 0, 1, 1]
>>> confidence = [1, 2, 3, 4, 4, 3, 2, 1]
>>> nRatings = 4
>>> nR_S1, nR_S2 = trials2counts(stimID, accuracy, confidence, nRatings)
>>> print(nR_S1, nR_S2)