Custom randomization: Selecting one item per condition

OS: Win10
PsychoPy version: 2020.2.4
Standard Standalone? (y/n) If not then what?: y, but will need to transfer online to Pavlovia
What are you trying to achieve?: custom randomization

Hi there,

I have an excel file with sentences for my stimuli. Each sentence has a positive and a negative version. I want the participants to only see one version of each sentence (chosen randomly; the order of the sentences should also be random for every participant). This is how the two main columns look in my Excel file:
image
Now, I came up with two potential ways of doing it:

  1. Using numpy random choice:
    Selected rows: $np.random.choice((‘POSITIVE’, ‘NEGATIVE’), size = 1)

  2. Specifying in a code component that if $NUMBER of the current dialog is already in the list of completed trials then skip to the next dialog until there are no dialogs left:
    Begin experiment: presentedNumbers=
    Begin routine: presentedNumbers.append(NUMBER)
    Each frame: MyTrial = getCurrentTrial()
    if MyTrial in presentedNumbers:
    continueRoutine = False

I must have made mistakes because with either method my experiment crashes. Can anyone please offer some help?

First I want to give you a heads up that numpys or pandas will not work when you switch your experiment over to Pavlovia because they don’t have javascript equivalents. So I would try to get rid of those asap to save future you a ton of time. Check out this crib sheet for help with that. I, personally, stopped using python altogether and only use javascript code components and test the code directly on Pavlovia instead of locally.

If I’m understanding you correctly, you’re trying to go through and pick one of two versions of a sentence. I would have two separate arrays, one for the neutral versions (neutral) and one for the unpleasant versions (unpleasant). Then, I would set up a third array (valence) with 1s and 2s randomized for the total number of trials. Then you could have a code component at the beginning of each trial:

if (valence[trialNum] === 1) { //1 = neutral
    sentence = neutral[trialNum];
} else {
    sentence = unpleasant[trialNum];
}

This way it will only pick one of the two sentences for each trial, depending on the valence condition for that trial. Hope that helps!

P.S. that code is written in javascript because that’s what I’ve been used to using now. The python translation should be pretty easy though, if you want to continue using python.

Hi sal, thanks for your reply! Sorry for a dumb question, but is there a simple way of adding stimuli to arrays without writing endless code with import xlrd, append, etc.? I already had to write a lot of custom code for recording participants’ text input, so it’s all getting very complex, especially since this would need to be translated to JS (I don’t speak it very well).

If you’re trying to read in full sentences, it’ll probably be best to read in the excel files. Also note that the ‘import’ function will not translate to javascript, so reading in excels is even more of an ordeal. You can get help with that in this thread or you can look at an experiment I made using word stimuli. My experiment might be confusing to look at since there’s a lot going on, but the code in the ‘setupStimuli’ routine is where I read in my words from excel files.