Poisson distribution jitter

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x): 2022.2.4
Standard Standalone? YES
What are you trying to achieve?: Jitter ISI that follows a Poisson distribution between 2-12 seconds.

Hi all,
I’d like to have a fixation cross that is jittered for a variable amount of time following a Poisson distribution between 2-12 seconds. I know I can use the numpy function random.poisson, but I’m not entirely sure how to implement it for the jitter.

Thank you in advance!

I’m not quite sure why you’d want to use the Poisson distribution for a task like this, as it samples from a discrete distribution rather than producing a continuous time value, and it is hard to get it to fit deterministically within an upper bound (unlike, say, sampling from a uniform or gaussian distribution, which can easily be scaled to get the kind of interval you want). If you want a distribution that is skewed towards lower values, there is probably a better choice out there.

But proceeding at your own risk, amend the suggestions below as you like to get the sampling part right, but we can help at least with implementing things (i.e. there is a caveat here that there is no guarantee that the upper bound will not exceed 12 s).

  • Insert a code component (from the “custom” component panel).
  • Shift the code component to be above the component you are using for your fixation cross (by right-clicking on its icon), because the value needs to be calculated before the fixation stimulus can refer to it.
  • In its “begin routine” tab, put something like:
    # this is the dodgy non-deterministic bit that could go out of range:
    jitter = np.random.poisson(lam = 2) + 2.0 # DANGER DANGER 🚨
    # need to manually save the value in the data file:
    thisExp.addData('jitter', jitter)
  • Then simply put $jitter in the duration field of your fixation stimulus, and set the duration field to update on every repeat.

If you are happy to accept a distortion in the upper tail, you could simply truncate any out-of-range values, e.g.

if jitter > 12:
    jitter = 12

Thank you @Michael this should work great. The reason I’m using the Poisson distribution (as opposed to a uniform distribution) is because I’m utilizing near-infrared spectroscopy, and I need to capture the BOLD response but don’t want the ISI to be too long for too many trials.