Go/no-go#
In a go/no-go task the animal either responds (go) or withholds, and on no-go trials withholding is the correct answer. This tutorial takes a go/no-go animal through the same pipeline as the 2-AFC tutorial and shows what changes: the task, how trials are scored, which statistics apply and which the library refuses.
The animal is synthetic: eight sessions in which go is correct for stimuli above the boundary, with the laser on
30% of trials, where it makes the animal more willing to go (it moves the curve’s midpoint by −0.2). From files,
the change is the config’s task block (type: go_nogo);
go_nogo_minimal.yaml is a complete example.
import matplotlib.pyplot as plt
import numpy as np
from behav_utils import (
GoNoGo,
Outcome,
PsychometricModel,
TrialArrays,
compute_psychometric_curve,
compute_stats,
filter_trials,
generate_synthetic_animal,
plot_psychometric_curve,
select_sessions,
)
from behav_utils.stats import PSYCHOMETRIC, SDT
model = PsychometricModel(mu=0.0, sigma=0.3, lapse_low=0.05, lapse_high=0.05, laser={'mu': -0.2})
animal = generate_synthetic_animal(model, n_sessions=8, trials_per_session=300, task=GoNoGo(),
laser_fraction=0.3, rng=1)
sessions = select_sessions(animal, min_trials=0)
off = filter_trials(sessions, trial_type='non_opto')
on = filter_trials(sessions, trial_type='opto')
arrays = TrialArrays.from_sessions(off)
arrays.n_trials, arrays.n_responded
(1613, 1613)
Every non-aborted trial counts as responded. A go is 1, and a blank that is not an abort is a withhold, 0, so it is scored rather than lost; a go/no-go session has no no-response trials:
codes, counts = np.unique(animal.sessions[0].trials.outcome, return_counts=True)
{Outcome(code).name: int(count) for code, count in zip(codes, counts)}
{'ERROR': 45, 'CORRECT': 237, 'ABORT': 18}
Statistics#
The statistics that need only a binary, scored response on a stimulus axis work as in 2-AFC: accuracy, the
psychometric fit and signal detection (dprime, criterion). Go/no-go adds its own: go_bias, the go rate
minus 0.5, and hit_minus_cr_rate, the hit rate minus the correct-rejection rate. The
statistics reference defines each.
compute_stats(arrays, ['accuracy', 'go_bias', 'hit_minus_cr_rate', *SDT, *PSYCHOMETRIC]).round(3)
accuracy 0.831
go_bias 0.008
hit_minus_cr_rate 0.017
dprime 1.917
criterion -0.034
mu -0.062
sigma 0.351
lapse_low 0.018
lapse_high 0.051
Name: value, dtype: float64
Statistics that assume two active choices are refused, and the error names the go/no-go counterpart where there is one (see Tasks, families and capabilities):
compute_stats(arrays, ['side_bias'])
---------------------------------------------------------------------------
RequirementError Traceback (most recent call last)
Cell In[4], line 1
----> 1 compute_stats(arrays, ['side_bias'])
File ~/work/behav_utils/behav_utils/src/behav_utils/stats/registry.py:213, in compute_stats(arrays, names, rng, strict)
211 entry = _PRODUCERS[_OUTPUT_TO_PRODUCER[n]]
212 if not entry.requires <= task.capabilities:
--> 213 require(task, entry.requires, n, entry.instead)
214 if rng is None:
215 rng = np.random.default_rng()
File ~/work/behav_utils/behav_utils/src/behav_utils/tasks/base.py:224, in require(task, needs, what, instead)
222 else:
223 parts.append('there is no counterpart for this task')
--> 224 raise RequirementError('; '.join(parts))
RequirementError: side_bias needs two_choices (both responses are active choices, as in 2-AFC); go_nogo has binary, scored, stimulus_axis, withhold; use go_bias instead
The psychometric curve#
For go/no-go the psychometric curve is P(go) against the stimulus:
curve = compute_psychometric_curve(arrays, n_bootstrap=200)
fig, ax = plt.subplots(figsize=(4.5, 3.5))
plot_psychometric_curve(curve, ax=ax, label='laser off')
ax.set_ylabel('P(go)')
ax.legend();
A laser contrast#
The laser was assigned trial by trial within the same sessions, so trials are a valid resampling unit and a permutation p is allowed (see Resampling units). The draws are kept small to keep the notebook quick; with 100 permutations the smallest possible p is 1/101, about 0.01.
from behav_utils import compute_delta_stat
from behav_utils.plotting import plot_psychometric_comparison
d = compute_delta_stat({'off': off, 'on': on}, ['go_bias', 'mu'], reference='off',
n_bootstrap=100, n_permutations=100)
plot_psychometric_comparison(d)
d.contrast('on').table().round(3)
| stat | diff | ci_lo | ci_hi | boot_p | perm_p | unit | |
|---|---|---|---|---|---|---|---|
| 0 | go_bias | 0.069 | 0.040 | 0.105 | 0.02 | 0.01 | trials |
| 1 | mu | -0.124 | -0.205 | -0.056 | 0.02 | 0.01 | trials |
Where to go next#
Continuous responses does the same for a task whose responses are values.
Tasks, families and capabilities explains why the library refuses what it does.
The statistics reference lists the statistics each built-in task refuses.