behav_utils.stats#
Scalar statistics on trial data.
compute_stats(arrays, names) returns a float pd.Series in request order, for example
compute_stats(arrays, [*PSYCHOMETRIC, 'accuracy']); the statistics reference lists every name.
Every statistic is a float. Multi-output fits (a psychometric fit, the
logistic history regression, the serial-dependence profile) expose each
output as its own name and run once per call. Array-valued readouts (update
matrix, conditional psychometrics, binned curves) are not statistics and live
in behav_utils.readouts.
Importing this package registers all built-in producers.
- behav_utils.stats.compute_stats(arrays, names=None, *, rng=None, strict=True)[source]#
Compute scalar statistics on one block of trials.
- Parameters:
arrays (TrialArrays) – the trials (pre-filtered).
names (Sequence[str] | None) – scalar stat names. Multi-output fitters run once regardless of how many of their outputs appear here. None: every statistic that applies to
arrays.task. A requested name whose needs the task lacks raisesRequirementError, whateverstrictsays.rng (Generator | None) – generator handed to every producer (stochastic ones draw from it; pass a seeded one for reproducibility). A fresh default generator is used when None.
strict (bool) – True raises on a producer error. False fills that producer’s outputs with NaN and continues — the resampling-loop path, where a failed refit is a discarded draw, not a crash.
- Returns:
float
pd.Seriesindexed bynamesin request order.- Return type:
Series
- behav_utils.stats.stat(name, *, exchangeable=True, requires=(), instead=None)[source]#
Register a statistic that returns one number, as a decorator on
f(arrays, *, rng) -> float.- Parameters:
name (str) – The statistic’s name, as requested in
compute_stats.exchangeable (bool) – Whether trials may be resampled for it, False when it depends on the order of trials.
requires (Iterable[str]) – The task capabilities it needs; empty for every task.
instead (Mapping[str, str] | None) – Maps a capability to a counterpart to suggest when a task with it is refused.
- Returns:
The decorator, which registers the function and returns it unchanged.
- behav_utils.stats.fit(name, *, outputs, exchangeable=True, requires=(), instead=None)[source]#
Register a fitter that returns several numbers, as a decorator on
g(arrays, *, rng) -> tuple.- Parameters:
name (str) – The fitter’s name.
outputs (Sequence[str]) – The names of its outputs, in the order of the tuple; each can be requested on its own.
exchangeable (bool) – Whether trials may be resampled for it, as for
stat.requires (Iterable[str]) – The task capabilities it needs, as for
stat.instead (Mapping[str, str] | None) – Counterparts to suggest on refusal, as for
stat.
- Returns:
The decorator, which registers the function and returns it unchanged.
- behav_utils.stats.list_stats(task=None)[source]#
Every scalar name that can be requested from
compute_stats().- Parameters:
task (Task | None) – Only the names whose needs this task provides; None for every name.
- Returns:
The names, in the order the statistics were registered.
- Return type:
List[str]
- behav_utils.stats.is_exchangeable(name)[source]#
Whether trial-level resampling is valid for a statistic.
- Parameters:
name (str) – The statistic’s name.
- Returns:
True unless it depends on the order of trials.
- Return type:
bool
- behav_utils.stats.fit_pse_dynamics(a, shape=None)[source]#
The
PSE_DYNAMICSvalues for one block.- Parameters:
a (TrialArrays) – The block’s trials.
shape –
(sigma, lapse_low, lapse_high)to pin the psychometric shape, so that only the criterion’s trajectory is fitted (three free parameters instead of six); None to fit all six.
- Returns:
The values, in the order of
PSE_DYNAMICS.- Return type:
tuple
Constants#
PSYCHOMETRIC, LOGISTIC_HISTORY, SD_PROFILE, PSE_DYNAMICS and SDT are tuples of the output names of the
fitters psychometric, logistic_history, sd_profile, pse_dynamics and sdt, to splat into a request, as in
compute_stats(arrays, [*PSYCHOMETRIC, 'accuracy']). The statistics reference lists
each fitter’s outputs.