0

I am working on an experiment and have parts of it built using some coder and some builder, but am stuck on a spot. The experiment presents two different lists of words to people (list A and list B) and each word in it's respective list is randomly paired with a number at the beginning of the experiment. Psychopy shows both the word and the number to participants and it is important that after they are randomly paired the word-number pairs are then yoked for the remainder of the experiment. I have used coder to randomize the pairing and construct a conditions file for the two word lists on the fly. Builder then uses these constructed conditions files to present the stimuli (words and numbers).

This is the part where I'm stuck. After the two word lists and their paired numbers are presented, I need to present a subset of both lists A and B as well as a third list of word-number pairs that was not previously presented. So, for example, a person might see something like this during the experiment:

First presentation: List A: frank - 1, susan - 3

List B: shoe - 2, dingy - 1

Second presentation: frank - 1, shoe - 2, hotel - 4

The beginning of the experiment is where coder is used to create the word and number lists as well as write the two list's condition files. That code is below:

import random
import csv

studylista=["shoe","bear","balls","dingy"]
pointslista=[1,2,3,4]

listaRand=random.sample(studylista,len(studylista))
listapointsRand=random.sample(pointslista,len(pointslista))

with open('WordsandPointslista.csv','wb') as w:
  writer=csv.writer(w)
  writer.writerow(['studylista','pointslista'])
  for i in range(len(listaRand)):
    writer.writerow([listaRand[i],listapointsRand[i]])

studylistb=["frank","robert","daniel","susan"]
pointslistb=[1,2,3,4]

listbRand=random.sample(studylistb,len(studylistb))
listbpointsRand=random.sample(pointslistb,len(pointslistb))

with open('WordsandPointslistb.csv','wb') as w:
  writer=csv.writer(w)
  writer.writerow(['studylistb','pointslistb'])
  for i in range(len(listbRand)):
    writer.writerow([listbRand[i],listbpointsRand[i]])

I need a random subset of the two previously presented lists along with an additional list that has not been presented to be seen all together by the participant. The previous word-number pairings for the already seen lists also need to be preserved. I cannot seem to discover how to do this.

I currently have the two word-number lists presented in separate routines with loops around each one. I am trying to figure out how to create a third routine that will show only some of the previously seen word-number pairs along with some new word-number pairs. Thanks.

Anchises
  • 15
  • 5
  • By "using some coder and some builder" do you actually mean that you are working entirely in Builder but inserting Code components? (Asking as that affects what libraries are already imported by Builder by default.) – Michael MacAskill Sep 30 '15 at 20:34
  • And could you edit to actually ask a question? It's not clear what the actual problem is. Presenting a subset of responses is a straightforward option in Builder loop dialogs. What is your precise difficulty with using a third list? – Michael MacAskill Sep 30 '15 at 20:38
  • Yes I am using builder entirely with the only code being what's written above. – Anchises Oct 02 '15 at 01:05

1 Answers1

0

In your code above, don't create two separate two-column CSV files, but combine them into a single four-column file. This file can be used in multiple loops. If I understand your design correctly, it would be used first in a loop to present all the 'A' word/number pairs, and then again in a second loop to present all the 'B' word/number pairs. Lastly, use it in a final loop to present just a subset of the 'A' & 'B' pairs. This subsetting is applied via the "Selected rows" field in the loop dialog. Randomisation is optional in the first two loops, as you have already shuffled the rows, but would likely be necessary in the third loop to avoid presenting rows in the same order as in the first two loops.

Then there is the question of how to handle the third set of word/number pairs. The easiest thing to do would be to simply create them at the same time as the A & B sets and stick them in the same CSV file. But in this case, you would need the same number of words and numbers, some of which wouldn't be presented due to only running through a subset in the final loop. The alternative is to have a second code component prior to the third loop which reads in the existing file, shuffles the rows, subsets it, and then adds the new columns. i.e. doing a lot of the things which the Builder loop would otherwise do for you, but allowing you not to 'waste' words, if that is important to you.

Lastly, I also simplified your code above. Builder already imports the numpy.radom.shuffle function, which is simpler than doing all the sampling and so on, and then you don't need to import the standard random library.

Michael MacAskill
  • 2,411
  • 1
  • 16
  • 28
  • Thanks. How do I randomize the second presentation? I used a text stim in builder with $texthere to call that column from the condition file. A second text stim is used to call the pointvalue for the numbers. How can I make it so that $texthere and $numberhere display something from either list A, B, or filler randomly? Is a coder component needed to set the text stim? I also need to ensure that this randomization is not with replacement. For example, I need half of list A, half of list B, and half of the filler list presented. If there is an occasional AA or BB order sequence that is ok. – Anchises Oct 07 '15 at 15:55
  • To clarify, list A, B, and a filler along with the points are now all in the same condition file, and I need to call a random A, B, or filler and set that randomly called condition in a text stim. – Anchises Oct 07 '15 at 15:57
  • You're now getting beyond what randomisation schemes Builder can implement "out of the box". e.g. it isn't designed to do sampling without replacement. That could probably be hacked by specifying a loop as "full random" and with nReps > 1, and then just presenting a subset. But that couldn't work with just showing half of the A & B lists. You'd need to construct a conditions file with just the entries you want. But you might find it easier to shift to Coder for full flexibility. – Michael MacAskill Oct 07 '15 at 20:17
  • To select which list to display from on a given trial, you could do something in code on each trial to set which columns to use, but hard to show that in a comment. – Michael MacAskill Oct 07 '15 at 20:23
  • Thanks. I'll make it as another question. – Anchises Oct 08 '15 at 12:17