macOS 10.12.4
Psychopy 1.84.2
I am designing a mixed-language lexical decision experiment in PsychoPy, and what I would like to do is counterbalance presentation orders across participants in order to control for lexical variables and order effects.
I originally posted a more general question, but since then I have researched the question more thoroughly. I have a rough idea of what the code should look like, but unfortunately, my Python is elementary, and I need help with (1) the syntax, (2) how to refer to columns in the conditions file, and (3) where to put this code in the experiment.
What I would like to do is, have each real word (positive response, correctAns = rshift), appear equally in four conditions across participants. Each word will only appear one time per participant, but I would like it to appear in condition A for participant 1, B for 2, C 3, D 4, A 5, etc.
The four “conditions” (I’m using the term here in an experimental sense, not the PsychoPy sense) I have are defined by the language of the previous response (1, 2), and whether the previous response was a word or nonword (correctAns = rshift, lshift). This should be true for each real word in each language. So, the four (eight) “conditions” are as follows:
1+, 1+
1-, 1+
2+, 1+
2-, 1+
1+, 2+
1-, 2+
2+, 2+
2-, 2+
(I don’t care too much about how the nonwords (-) appear, so they are not included in this list).
I have made an attempt at what the code should look like, but I know very little Python. What I need, as I said above, is to (1) fix the syntax to make it actually Python, (2) properly reference the other conditions (language, correctAns) for a given item (these are other columns in the conditions file, in addition to word), and (3) know where to put this in the code.
For each participant, I will give them a number 1-4 and enter this upon starting the experiment. I hope to have ~20 total participants.
If you could help me with writing the code, I would GREATLY appreciate it. Thank you so much.
(As a note, in the code below, I put the range as 4-457 even though I have a total range of 0-467 because I wanted to guard against it being stuck if only a few items remained but the conditions could not be fulfilled.)
r = (trials.thisIndex + thisExp.participant) % 4
For i in range(4, 457):
If correctAns == ‘rshift’:
If r == 0 and thisTrial.language == thisTrial.language(i-1) and thisTrial.correctAns == thisTrial.correctAns(i-1):
Return True
If r == 1 and thisTrial.language != thisTrial.language(i-1) and thisTrial.correctAns == thisTrial.correctAns(i-1):
Return True
If r == 2 and thisTrial.language == thisTrial.language(i-1) and thisTrial.correctAns != thisTrial.correctAns(i-1):
Return True
If r == 3 and thisTrial.language != thisTrial.language(i-1) and thisTrial.correctAns != thisTrial.correctAns(i-1):
Return True
Else:
random.shuffle
Repeat
Please let me know if you need a copy of my conditions file, psyexp file, etc. Thank you.