| Reference | Downloads | Github

Random routines

OS: Win10
PsychoPy version: 3.1.2

I am trying to construct an experiment in which there will be 20 base rate neglect tasks, each following the memory task and metacognition assessment + 3 practice tasks. In short, each task is a routine. I am wondering, is there a way to make routines random for each participant? And if so, I would like to have tasks following each other not randomized - in other words, there are ‘‘task pairs’’ (actually, there are 3 tasks - base rate, memory task and metacognition assesment) which I would like to treat as one task, while randomizing.

I am sorry if I am not being clear. Thank you in advance.

This sounds unwieldy. If at all possible, you should aim to reduce this amount of repetition, it is usually a sign of an inefficiently-coded experiment. i.e. are the 20 tasks actually completely different? Or do they share a similar structure, and could be presented with a smaller number of routines, where stimuli and other conditions are controlled in a way that allows the 20 tasks to be expressed?

Yes. You can insert a code component on each routine (from the “custom” component tab in Builder), and in its “Begin routine” tab, insert something like this:

if not some_condition:
    continueRoutine = False

i.e. before each routine even starts, you can run a check as to whether it should immediately terminate and go on to the next one. We would need to know more about the logic of your experiment to suggest the exact condition to use. But, for example, you might put the name of the task to run on each trial in a column in your conditions file (called, say, task_name), and then check that:

if task_name != 'the_name_of_this_routine':
    continueRoutine = False

Thanks for your answer.

I am not sure if I can use less routines - 20 tasks have similar structure but they are different substantially (participants are presented with 20 different base rates - for example: “Person A is funny. There are 790 accountants and 210 clowns in the study. Is person A more likely to be an accountant or a clown?”).

Yes, that sounds exactly like it should be one routine. Instead of specifying fixed values for the text stimulus, you simply control the values that are presented on a trial-by-trial basis, either using variables in a conditions file (most likely, and easiest), or via some code snippets.

This not only simplifies the creation and maintenance of your experiment, but will dramatically ease things at the data analysis stage, as your data output file will be much better structured.

Come back to us with more details of your task if you need more assistance with implementing it. But for a start, your conditions file could look something like this:

attribute  first_n  first_profession  second_n  second_profession
funny      790      accountants       210       clowns
boring     210      accountants       790       clowns
asinine    100      economists        600       bloggers
# etc etc

Then in your text stimulus, you could put in an expression like this in the text field, set to update on every repeat:

$f'Person A is {attribute}. There are {first_n} {first_profession} and {second_n} {second_profession} in the study. Is person A more likely to be an {first_profession[:-1]} or a {second_profession[:-1]} ?'

i.e. you mix your fixed sentence elements with variables from the condition file attached to the loop controlling your trials.

In this case, we automatically trim the “s” from the professions on their second occurrence, but this might be a bit crude.

These formatted “f strings” are a feature of Python 3, so you need to be using the Python 3 version of PsychoPy to use this. Otherwise, they need to be formatted using Python 2 syntax.

1 Like