Randomizing trials without conditions in a loop

OS (e.g. Win10): Mac OS 10.15 Catalina
PsychoPy version (e.g. 1.84.x): PsychoPy v2020.1.0
Standard Standalone? no If not then what? brew install

What are you trying to achieve?:
I try to build a heartbeat counting task (Schandry,1981) on PsychoPy.
It is a task, which the participant counts his/her heartbeats silently during different time durations. (20,25,35,45,55,65 and 75 seconds) I built an experiment, which I can present the blocks with different time durations randomly.

What did you try to make it work?:
The basic structure is as follows:

  • introduction
  • counting20
    • sound_start20 → The participant hears a beep signal
    • text_start20 → a text telling the participant to start counting (5sec.)
    • text_count20 → blank page during the counting time (15sec.)
    • sound_stop20 → the beep signal indicating to stop counting
    • text_stop20 → the text telling the participant to stop counting
  • counting25
    • sound_start25
    • text_start25
    • text_count25
    • sound_stop25
    • text_stop25
  • Counting 35s
  • Finish

I have 7 counting routines in total with different time durations. (The only difference among them is the time duration in text_count)
After building my routines, I inserted a loop from the first counting routine (counting20) to the last counting routine (counting75). I chose the loop name as loop_mix and the loopType as Random. I do not need any other conditions, so I did not load any xlsx file to Conditions. Basically, there is not a stimulation, I need to keep track of the time while doing neuroimaging recording. It is important to present each time block once and randomly.


What specifically went wrong when you tried that?:
I expected it to present counting routines in the loop_mix in a randomized order (for example: counting45, counting25, counting35, counting55, counting75, counting20, counting65)

Though, whenever I run it, it shows the trials in the order I built them as: counting20-counting25-counting35-counting45-counting55-counting65-counting75

I also tried other loopTypes. The result did not change.

I am new to PsychoPy and programming. I cannot figure out why randomizing in the loop did not work as I planned. I checked the documents but I could not find any solution. The tutorials are about randomizing the conditions stored in xlsx files. I need randomizing for the trial blocks. I hope that I could explain my problem clearly. Could you please help me?

Your routines are necessarily presented in a fixed order, as shown in the time line. The randomisation option refers to how the rows extracted from a conditions file are ordered. You don’t have a conditions file, so the loopType will have no effect here, regardless of the option you select.

There are ways to randomise the order of multiple routines on the timeline, using some snippets of custom code. But I wouldn’t advise doing that here. The issue is that you are kind of fighting against the way that Builder is designed to work. What would be better is to actually use a conditions file. That way you could delete 6 of your 7 “counting” routines. Just keep one, but set the durations of stimuli with a variable, rather than with fixed values. That variable would come from your conditions file, and would automatically give you the random ordering you want, without the need for any custom code at all.

These things are not incompatible. In most situations, randomising the order of blocks is indeed based upon using conditions files.

Excellent, then this is perfectly set up for controlling that duration via a conditions file.

A good rule of thumb in any aspect of computer programming (and under the hood, you are indeed creating a computer program here) is that if you are duplicating a lot of things (in this case, routines that differ in only one aspect), then something is going wrong. In this case, you can achieve what you want with a single routine. This makes it far less likely that you would accidentally introduce an error in the many duplicated routines, and will also greatly simplify your data analysis process, as all of your dependent variables will wind up in the same columns in the resulting data file. By using multiple routines, the responses would all end up in different columns and the data file would be hard to work with.

If it still isn’t clear how to implement what you need, please let us know.

1 Like

Hi Michael,

Thank you so much! That helps a lot.

I write what I did here, in case someone face a similar situation.
I designed my experiment as shown below and created an xlsx file:

I chose loopType as random and nReps$:1.

In the counting routine, text_counting component, I set the start as: time(s): 0 and sto as duration(s) and typed $duration (to set a variable from my xlsx file)


Defining the onset/duration of components — PsychoPy v2021.2 → This document was also helpful

Glad that worked for you - the experiment now looks much more elegant and should be more reliable and easy to analyse as a result.

Hi both, I am a newbie with PsychoPy and I am working on a similar task right now but from another version of PsychoPy (PsychoPy3 v2021.1.2).

I followed this conversation and reproduced the settings posted by @ozge following @Michael advice.

However, when trying to add the variable $myDuration from my conditions file

I am running into the following error: if tThisFlipGlobal > Instructions.tStartRefresh + asarray($myDuration)-frameTolerance:

Do you have any idea how to solve this issue?

Thank you very much for your help.

Julia

Hi Julia,
Remove the dollar sign from stop field. I believe these fields now support variables by default.

Thank you very much @filiabel for this information.
It’s working perfectly fine now :slight_smile: