Between Subjects: Use subject number as an index for conditions


I am working on the lineup portion of an eyewitness identification task in PsychoPy. This is a completely between subjects design.

My goal:

Ideally, I’d like to use the participant number entered via the dialog box at the beginning to reference a specific excel file with one row defining conditions and then only display the conditions for that particular subject (or a specific row with one excel file listing all conditions for all subjects). Basically, I would like to suppress the within-subjects loop structure, and use the subject number to call the right excel file (like Sub1, below) for subject 1, Sub2 for subject 2, and so on.

Current state:

Currently, I have a nested loop structure, which displays the four lineup members at once.

Figure A

Figure B
Was of the excel file. SubjNumList column had words “Sub1” and Sub2 in rows 1 and 2 for example.

The outer loop, trials, references the Kaiser_cond condition list (Figure A and B), which specifies another excel file that has one row with the image components that that particular subject will see.

The inner loop, lineup, uses $SubjNumList+’xlsx’ to choose the excel file (Figure C) that corresponds to that condition.

Figure C

Right now, I’m just building this with 2 subjects as indicated by Figure B.

Of course, using the current loop structure, each subject sees each condition (each spreadsheet with conditions, Sub1, Sub2,…SubN).


I only want each subject to see the conditions associated with their subject number. Is it possible to do this in via builder? If so, how?

If not, what is the natural way to do this in the coder (as I am unfortunately new to Python)?

Example in Matlab PTB:

In matlab ptb, I do the following:


Upload conditions from one excel spreadsheet (relevant ones are bolded):

[TLg,TRg,BgL,BRg,SP,HSFP, MSFP, LSFP,NB, TB,TL,TR,BL ,BR,LT,SC] = textread(conditionsfilename,’%s%s%s%s%d%d%d%d%s%s%s%s%s%s%s%d’,‘delimiter’,’,’);%upload conditions

SubjNum=str2num(SUBJECT);%capture the subject number for row index

%Use the subject number to index the positions of each member, TL is top left, TR is top right,etc.

memb1= TL (SubjNum);

memb2= TR (SubjNum);

memb3= BL (SubjNum);

memb4= BR (SubjNum);

LineupMembers =[memb1, memb2, memb3, memb4];

for i=1:length( LineupMembers ) %for loop that opens each picture and makes a texture for it.

LineupMember{i} = imread(LineupMembers{i});

tex(i) = Screen(‘MakeTexture’, window, LineupMember{i});


%%Start simultaneous lineup

Screen(‘TextSize’, window, 20);

%sets positions and draws each lineup member in the 4 positions.

Screen(‘DrawTextures’, window, tex ([1 2 3 4]), ,[P14Lt toprowHt P14RT toprowpicbot;P36Lt toprowHt P36RT toprowpicbot; P14Lt bottomrowHT P14RT bottomrowpicbot; P36Lt bottomrowHT P36RT bottomrowpicbot]’);


Would there be some comparable way to accomplish using the subject number as the index in PsychoPy, or is my Matlab PTB code causing interference for me?

So the first thing you need is some way to translate the participant number to an index for your conditions. If you want the same proportion, this is relatively easy, just do this:

expInfo['participant'] % numConditions

This divides one by the other and supplies the remainder. So if you had 3 conditions and this was your 8th participant, for example, you would get 2 (8-6).

The way conditions files work is that, each loop, it creates a variable for each column and sets its value to be the value of that column at the row corresponding to the current trial. So what you need is to get the same columns but for different conditions into an array, such as a list or tuple, then index this array. If we say that you want to have half of participants see stimuli from columnA and half from columnB, you would make a list at the start of the routine:

columnsAB = [columnA, columnB]

and then set the stimulus value to index this list using the number we created earlier:

$columnsAB[ expInfo['participant'] % 2 ]

You can do all this in Builder! Just create a Code component and put the code for creating the list in the Begin Routine tab, then make sure your stimulus’s value is set to Set Each Repeat.

Thanks very much for your reply!

One thing I should mention, is that the stimuli for each participant includes 4 individual image components on just one trial, same screen. The spreadsheet holds the image file name for Position 1 through 4, in separate columns.

So, from PsychoPy’s perspective, it’s not that half see A and half see B, rather subject 1 sees the mugshots 1, 2, 3, and 4, in positions 1, 2, 3, and 4 on the screen. They make a response, then the experiment ends for that subject. (All real counterbalancing happens outside of PsychoPy, in R, which generates the spreadsheets).

I think the separate nature of my stimuli might not work with the code component described in your solution–unless I have misunderstood, which is probably the case.

I did attempt a modification of how I index the Image, as shown below, but I think my reasoning is wrong. So it is not the case that expInfo[‘participant’] is the value entered into the dialog box? If I am subject 2, then int(expInfo[‘participant’] ) will not be 2?

Thanks again–I am continuing to look into your code component advice.

I understand the code component advice now. I have to change how I represent conditions in Excel. I previously had each row of the spreadsheet correspond to conditions for each individual subject, (e.g. row 1 col 1 indicates mugshot image filename for position 1 on subject 1’s lineup, row 1 col2 has image filename for image in position 2 for subject 1, and so on).

Now, each column represent one of the 36 possible conditions in my spreadsheet, which means I have to make the 36 lineups by hand and enter them as one jpg. Got it.

New question: when data are saved, the csv file lists all possible conditions (entries in columns from the conditions file) rather than the entry that the participant saw. How can I have PsychoPy save only the filename of the stimulus that the individual subject actually saw?