YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Build your first PsychoPy experiment (Stroop task)

This tutorial shows you the basics and how to build a complete experiment from scratch in PsychoPy (in just 15 minutes). See also the documentation at http://www.psychopy.org

This is the first video tutorial I've made. Apologies for all the extraneous mouse movements!

Get Embed Code
3 Languages

Showing Revision 4 created 11/28/2012 by Kevin Cole.

  1. Hi. My name's John Pierce.

  2. I'm a lecturer at the University of Nottingham.
  3. I'm the inventor of PsychoPy.
  4. In this demo, I'll show you how to
  5. create a simple experiment in PsychoPy.
  6. We're going to use the Stroop effect.
  7. When you first start up PsychoPy,
  8. you'll find two windows come open:
  9. One is the builder view, which allows you to
  10. construct your experiments graphically.
  11. And the other is the coder view, which allows you to
  12. create your experiments using Python scripts
  13. if you prefer to write code directly.
  14. Today we're going to be using the builder view.
  15. The builder view has three panels.
  16. It's got components. It's got one or more routines.
  17. Here we've got a single routine called the "trial".
  18. And it's got a flow which allows you to
  19. combine multiple routines together.
  20. In the case of the Stroop task, we'll need a
  21. a text object as part of our trial
  22. because we need to present a word to the subjects.
  23. So, let's create a text object.
  24. We'll call it "target". We'll have it start at
  25. maybe naught point five seconds,
  26. and it will last for five seconds.
  27. Notice that each of these parameters,
  28. as I hover my mouse over them, it gives me a tip to
  29. inform me about what I would be expected to include.
  30. There's also a help button. If I click on that,
  31. I'll go to the PsychoPy web site where it will tell me
  32. more detailed information about how to use
  33. this particular component.
  34. For now, we're not going to set color and the text
  35. of this text object. We'll come back to that
  36. later on.
  37. Having hit "OK", we can see the text object
  38. appearing in our routine and if we want to edit
  39. that, we can click on the icon again and we
  40. can get back and change our stimulus.
  41. Maybe we want it to be for four seconds, instead of for five.
  42. So it's now changed that representation.
  43. We also, for the Stroop task, need for the
  44. subjects to respond. So let's add a keyboard
  45. to this routine. We'll call it "response".
  46. We'll also start that at naught point five seconds.
  47. We don't want subjects to respond before
  48. the target was presented.
  49. I'm going to set this to have an infinite duration.
  50. If we set that to be blank, then the keyboard
  51. will be available forever.
  52. We're going to leave the allowed keys for now.
  53. I'll come back and change those later on,
  54. once we've set up our trials.
  55. OK, now we that the response is going to
  56. last forever.
  57. So, that's roughly what one trial is going to look like
  58. in the Stroop task. But we need to run more
  59. than one trial and right now we've got that
  60. routine appearing just once on our flow.
  61. Let's insert a loop around the trial,
  62. so that we can repeat it.
  63. If I click on "Insert loop" just once,
  64. and select, again with a single click,
  65. where we want our loop to start and stop.
  66. It brings up a dialog box, asking me
  67. what do I want to call this loop.
  68. We'll call it "trials". That's fine.
  69. Should it be random or sequential in choosing the next condition?
  70. Random is fine.
  71. We'll have five repeats, and we need to
  72. go and specify our conditions file.
  73. Now, you'll notice here it's asking for a trial
  74. a file that's CSV or XLSX. We need to go off
  75. to Excel in order to create our file.
  76. And click "OK". You'll see it insert the
  77. loop around the trial.
  78. Let's go and save that experiment now,
  79. so that we don't lose it.
  80. Save. I'm going to create a new folder on
  81. my desktop called "Stroop" and maybe I'll
  82. call the file "Stroop Experiment".
  83. Okay.
  84. The easiest way to define the conditions for
  85. your experiment is to use a spreadsheet package
  86. like Excel.
  87. We can create a number of parameters for
  88. our experiment, such as the word that we're
  89. going to present, or the color that it will
  90. be presented in, and we can create a number
  91. of different conditions. We specify one on each row.
  92. So, for the Stroop task, we might use the word "red"
  93. written in red. We might have the word "red" written
  94. in green. We might have the word "green"
  95. written in green, etc.
  96. "Green" in blue. "Blue" blue. "Blue" and red.
  97. I'm going to keep track of whether or not
  98. those are congruent. We don't really need to do this.
  99. We could always work it out later, but it's
  100. kind of convenient to have that stored as well.
  101. So, congruent and I'm going to say "1";
  102. that means "true"; and "0" for "false".
  103. That's just going to help us later on.
  104. Now we also need to specify what's the
  105. correct answer, cause PsychoPy will want to know
  106. whether or not the subject got it right or wrong.
  107. I'm going to call that "corrAns".
  108. These parameters can't use any punctuation
  109. or spaces in their names. So, I'm going to
  110. take away the space and give it a capital letter
  111. for, uh, to specify the correct answer.
  112. In this case, we're going to use the left,
  113. down, and right cursor keys from the keyboard.
  114. So, I'm going to specify that red -- and remember
  115. in the Stroop task that the subjects are asked
  116. to report the color of the text rather than
  117. the word itself. So, when the color is red, I'm
  118. going to ask the subjects to press "left".
  119. That's the left cursor key.
  120. When it's green they should press "down".
  121. "Down" again.
  122. When the color's blue they should press "right".
  123. "Right".
  124. And now I've got red again, so they should
  125. press "left".
  126. Okay, that defines six different conditions
  127. for our experiment with four different parameters.
  128. Okay, let's save that file.
  129. I'm going to put it in the same folder as my
  130. experiment, although you don't have to.
  131. And I'm going to call it "conditions.xlsx".
  132. It's very important that you save it
  133. in the XLSX format. PsychoPy can't use the old
  134. XLS style spreadsheets.
  135. Click "Save" and we're done.
  136. So now we need to show PsychoPy where that file
  137. is, and how to use it during the trials.
  138. The way to do that is with the loop dialog.
  139. So, if I just click on that loop again,
  140. we'll get the properties back for the loop
  141. and there's a conditions file. If we browse,
  142. we can select our file that we've just created,
  143. open that, and it's told me that there are
  144. six conditions with four different parameters.
  145. The parameters are color, word, congruent
  146. and correct answer.
  147. Ok? If the file had been invalid in some way,
  148. maybe we had a space in one of our column
  149. headings, then we would get a warning here to
  150. say that we couldn't use that file or it
  151. wouldn't show us the parameters were there.
  152. Now we can select "OK". It's showing that we've
  153. got five times six random trials.
  154. So, five different repeats of six different conditions.
  155. Okay, so the conditions file is now being set
  156. here on each repeat through the loop, we use
  157. a different row.
  158. We still need to tell the stimulus about the
  159. parameters that it needs to use.
  160. We want the color of our stimulus to be set
  161. by that color parameter. Now, I've typed in
  162. "$colour" here, spelt with a "u" because that's
  163. how we spelt it in the Excel file.
  164. And that "$" is to tell PsychoPy "This isn't a
  165. literal value. It's a variable."
  166. Okay? So, it's going to go off and find a
  167. variable called "colour" and see what the current
  168. value of that variable is.
  169. It's going to be red or green or blue.
  170. I'm also going to set that to change on every repeat
  171. rather than being constant.
  172. Okay? We don't want the stimulus just to be
  173. fixed to one particular color for the entire experiment.
  174. Similarly, the text of this text stimulus should be
  175. the word that we've specified in the Excel file
  176. and it shouldn't be "word" it should be the variable
  177. "word" in order to go and fetch that variable
  178. which is going to be red or green or blue.
  179. And, again, we want that to change on every repeat
  180. of this routine.
  181. Okay. We also need to set the response to be
  182. based on the conditions. So I need to change
  183. the keys that are going to be allowed for
  184. the subject to respond with. We don't want them
  185. to use the "yes" or the "no". We want them to use
  186. "left", "right" and "down". So, notice that any keys
  187. I want to put here I separate by commas and
  188. I have to put inverted commas around the names
  189. of each of the keys.
  190. If I leave that blank -- the entire box -- then all keys
  191. will be available. Okay? So that allows the subject
  192. to press any key. I've also got "forceEndRoutine"
  193. checked here. We left the response to be
  194. infinite but as soon as they press any key,
  195. it will force the end of that trial.
  196. So that's a useful thing for us to do.
  197. We're also going to want to store correct.
  198. So, if I check that box, we have to tell PsychoPy
  199. what is the correct answer on this trial,
  200. and if you remember, that was stored as "corrAns".
  201. Again, we need to use "$corrAns" to specify
  202. the fact that this is a variable name not,
  203. it shouldn't be looking for a key called "corrAns"
  204. cause it will never find one. It's got to use
  205. the variable "corrAns". And that's us done. Okay.
  206. Save. Okay, we're pretty much there.
  207. That should be a working experiment, but we do also
  208. want to provide the subject with some instructions.
  209. I'm going to insert another routine into the flow.
  210. When I click that button it shows me either "new"
  211. or "trial". Let's select "new" and I'll call it
  212. "instructions"... if I can spell it. "Instructions".
  213. It asks where I want to insert the instructions.
  214. We don't want it to be here because that would
  215. repeat the instructions on every trial.
  216. Let's put it before the loop. And now we can click
  217. on the instructions routine and we can edit that.
  218. So, we're going to want another text object.
  219. We're going to call that, say, "instrText",
  220. start at time zero. Duration, we'll make it infinite.
  221. Color white, that's fine. And we'll give it the text
  222. "Remember choose the color of the letters,
  223. ignoring the word:
  224. left = red, down = green, right = blue.
  225. Okay.
  226. Now because we've made that text last forever,
  227. we gave it an infinite duration, we need to make
  228. sure that the subject can get rid of them.
  229. So, we'll click on a keyboard, we'll allow any key,
  230. we'll force the end of the routine, and we won't
  231. bother storing anything.
  232. We make that last forever.
  233. Okay.
  234. If you do get that wrong, you should always be able
  235. to hit "escape" and you will still be able to quit
  236. the experiment without having to
  237. restart your computer.
  238. Okay, I'm going to save that again.
  239. I think we're done.
  240. Okay, let's just have a quick look at the
  241. Experiment Settings dialog box.
  242. In this dialog, you can control things like whether
  243. or not the mouse is visible during the experiment,
  244. the color of the background of the screen,
  245. whether or not it's in a window or in full screen,
  246. is it "screen 1" or "screen 2" if you've got
  247. multiple monitors, and what sort of data files
  248. you want to save out. So, lots of useful things there
  249. to control your experiment.
  250. Now, at this point we could construct a script.
  251. That'll allow you to go off and maybe learn a little
  252. bit about how Python works. It's about 220 lines
  253. long, this particular experiment. So, not too
  254. complicated a script. But we don't need to.
  255. We could actually go off and run our experiment
  256. by hitting the green man.
  257. Often takes a few seconds, especially the first time
  258. you run. So, be patient with that one.
  259. There we go. We've got a dialog box come up
  260. asking for the participant and the session number.
  261. That was also being controlled in the Experiment
  262. Settings dialog.
  263. I'm not actually going to run the experiment.
  264. I'll leave that to you.
  265. Okay. Have you found that useful?
  266. Check out the Demos menu for more ideas
  267. and I hope you enjoy using PsychoPy!