1 00:00:01,132 --> 00:00:02,897 Hi. My name's John Pierce. 2 00:00:02,897 --> 00:00:04,347 I'm a lecturer at the University of Nottingham. 3 00:00:04,347 --> 00:00:07,430 I'm the inventor of PsychoPy. 4 00:00:07,430 --> 00:00:08,648 In this demo, I'll show you how to 5 00:00:08,648 --> 00:00:09,982 create a simple experiment in PsychoPy. 6 00:00:09,982 --> 00:00:11,829 We're going to use the Stroop effect. 7 00:00:11,829 --> 00:00:14,575 When you first start up PsychoPy, 8 00:00:14,575 --> 00:00:17,293 you'll find two windows come open: 9 00:00:17,293 --> 00:00:19,907 One is the builder view, which allows you to 10 00:00:19,907 --> 00:00:22,285 construct your experiments graphically. 11 00:00:22,285 --> 00:00:25,250 And the other is the coder view, which allows you to 12 00:00:25,250 --> 00:00:27,604 create your experiments using Python scripts 13 00:00:27,604 --> 00:00:29,802 if you prefer to write code directly. 14 00:00:29,802 --> 00:00:32,864 Today we're going to be using the builder view. 15 00:00:32,864 --> 00:00:37,052 The builder view has three panels. 16 00:00:37,052 --> 00:00:41,437 It's got components. It's got one or more routines. 17 00:00:41,437 --> 00:00:43,419 Here we've got a single routine called the "trial". 18 00:00:43,419 --> 00:00:45,809 And it's got a flow which allows you to 19 00:00:45,809 --> 00:00:51,985 combine multiple routines together. 20 00:00:51,985 --> 00:00:53,780 In the case of the Stroop task, we'll need a 21 00:00:53,780 --> 00:00:56,300 a text object as part of our trial 22 00:00:56,300 --> 00:00:58,279 because we need to present a word to the subjects. 23 00:00:58,279 --> 00:01:00,521 So, let's create a text object. 24 00:01:00,521 --> 00:01:03,869 We'll call it "target". We'll have it start at 25 00:01:03,869 --> 00:01:06,107 maybe naught point five seconds, 26 00:01:06,107 --> 00:01:09,127 and it will last for five seconds. 27 00:01:09,127 --> 00:01:11,626 Notice that each of these parameters, 28 00:01:11,626 --> 00:01:14,036 as I hover my mouse over them, it gives me a tip to 29 00:01:14,036 --> 00:01:18,440 inform me about what I would be expected to include. 30 00:01:18,440 --> 00:01:21,366 There's also a help button. If I click on that, 31 00:01:21,366 --> 00:01:24,379 I'll go to the PsychoPy web site where it will tell me 32 00:01:24,379 --> 00:01:27,181 more detailed information about how to use 33 00:01:27,181 --> 00:01:29,760 this particular component. 34 00:01:29,760 --> 00:01:33,182 For now, we're not going to set color and the text 35 00:01:33,182 --> 00:01:36,763 of this text object. We'll come back to that 36 00:01:36,763 --> 00:01:39,292 later on. 37 00:01:39,292 --> 00:01:42,700 Having hit "OK", we can see the text object 38 00:01:42,700 --> 00:01:45,556 appearing in our routine and if we want to edit 39 00:01:45,556 --> 00:01:48,177 that, we can click on the icon again and we 40 00:01:48,177 --> 00:01:50,975 can get back and change our stimulus. 41 00:01:50,975 --> 00:01:53,857 Maybe we want it to be for four seconds, instead of for five. 42 00:01:53,857 --> 00:01:56,734 So it's now changed that representation. 43 00:01:56,734 --> 00:02:01,224 We also, for the Stroop task, need for the 44 00:02:01,224 --> 00:02:04,333 subjects to respond. So let's add a keyboard 45 00:02:04,333 --> 00:02:09,952 to this routine. We'll call it "response". 46 00:02:09,952 --> 00:02:13,465 We'll also start that at naught point five seconds. 47 00:02:13,465 --> 00:02:14,617 We don't want subjects to respond before 48 00:02:14,617 --> 00:02:17,176 the target was presented. 49 00:02:17,176 --> 00:02:21,162 I'm going to set this to have an infinite duration. 50 00:02:21,162 --> 00:02:24,342 If we set that to be blank, then the keyboard 51 00:02:24,342 --> 00:02:26,519 will be available forever. 52 00:02:26,519 --> 00:02:30,444 We're going to leave the allowed keys for now. 53 00:02:30,444 --> 00:02:32,394 I'll come back and change those later on, 54 00:02:32,394 --> 00:02:34,183 once we've set up our trials. 55 00:02:34,183 --> 00:02:41,268 OK, now we that the response is going to 56 00:02:41,268 --> 00:02:43,097 last forever. 57 00:02:43,097 --> 00:02:47,387 So, that's roughly what one trial is going to look like 58 00:02:47,387 --> 00:02:50,182 in the Stroop task. But we need to run more 59 00:02:50,182 --> 00:02:52,221 than one trial and right now we've got that 60 00:02:52,221 --> 00:02:54,453 routine appearing just once on our flow. 61 00:02:54,453 --> 00:02:57,761 Let's insert a loop around the trial, 62 00:02:57,761 --> 00:03:00,414 so that we can repeat it. 63 00:03:00,414 --> 00:03:02,569 If I click on "Insert loop" just once, 64 00:03:02,569 --> 00:03:05,299 and select, again with a single click, 65 00:03:05,299 --> 00:03:08,597 where we want our loop to start and stop. 66 00:03:08,597 --> 00:03:12,637 It brings up a dialog box, asking me 67 00:03:12,637 --> 00:03:14,557 what do I want to call this loop. 68 00:03:14,557 --> 00:03:16,414 We'll call it "trials". That's fine. 69 00:03:16,414 --> 00:03:21,448 Should it be random or sequential in choosing the next condition? 70 00:03:21,448 --> 00:03:22,961 Random is fine. 71 00:03:22,961 --> 00:03:25,686 We'll have five repeats, and we need to 72 00:03:25,686 --> 00:03:27,573 go and specify our conditions file. 73 00:03:27,573 --> 00:03:30,134 Now, you'll notice here it's asking for a trial 74 00:03:30,134 --> 00:03:33,963 a file that's CSV or XLSX. We need to go off 75 00:03:33,963 --> 00:03:36,485 to Excel in order to create our file. 76 00:03:36,485 --> 00:03:40,418 And click "OK". You'll see it insert the 77 00:03:40,418 --> 00:03:42,509 loop around the trial. 78 00:03:42,509 --> 00:03:45,481 Let's go and save that experiment now, 79 00:03:45,481 --> 00:03:47,937 so that we don't lose it. 80 00:03:47,937 --> 00:03:53,579 Save. I'm going to create a new folder on 81 00:03:53,579 --> 00:04:00,620 my desktop called "Stroop" and maybe I'll 82 00:04:00,620 --> 00:04:05,142 call the file "Stroop Experiment". 83 00:04:05,142 --> 00:04:09,026 Okay. 84 00:04:09,026 --> 00:04:14,455 The easiest way to define the conditions for 85 00:04:14,455 --> 00:04:18,914 your experiment is to use a spreadsheet package 86 00:04:18,914 --> 00:04:20,360 like Excel. 87 00:04:20,360 --> 00:04:22,461 We can create a number of parameters for 88 00:04:22,461 --> 00:04:25,397 our experiment, such as the word that we're 89 00:04:25,397 --> 00:04:27,803 going to present, or the color that it will 90 00:04:27,803 --> 00:04:30,862 be presented in, and we can create a number 91 00:04:30,862 --> 00:04:34,064 of different conditions. We specify one on each row. 92 00:04:34,064 --> 00:04:38,328 So, for the Stroop task, we might use the word "red" 93 00:04:38,328 --> 00:04:43,789 written in red. We might have the word "red" written 94 00:04:43,789 --> 00:04:48,140 in green. We might have the word "green" 95 00:04:48,140 --> 00:04:51,279 written in green, etc. 96 00:04:51,279 --> 00:05:04,370 "Green" in blue. "Blue" blue. "Blue" and red. 97 00:05:04,370 --> 00:05:08,024 I'm going to keep track of whether or not 98 00:05:08,024 --> 00:05:10,101 those are congruent. We don't really need to do this. 99 00:05:10,101 --> 00:05:12,668 We could always work it out later, but it's 100 00:05:12,668 --> 00:05:15,548 kind of convenient to have that stored as well. 101 00:05:15,548 --> 00:05:17,631 So, congruent and I'm going to say "1"; 102 00:05:17,631 --> 00:05:20,634 that means "true"; and "0" for "false". 103 00:05:20,634 --> 00:05:25,364 That's just going to help us later on. 104 00:05:25,364 --> 00:05:28,066 Now we also need to specify what's the 105 00:05:28,066 --> 00:05:30,575 correct answer, cause PsychoPy will want to know 106 00:05:30,575 --> 00:05:33,663 whether or not the subject got it right or wrong. 107 00:05:33,663 --> 00:05:39,719 I'm going to call that "corrAns". 108 00:05:39,719 --> 00:05:43,766 These parameters can't use any punctuation 109 00:05:43,766 --> 00:05:47,543 or spaces in their names. So, I'm going to 110 00:05:47,543 --> 00:05:50,577 take away the space and give it a capital letter 111 00:05:50,577 --> 00:05:53,960 for, uh, to specify the correct answer. 112 00:05:53,960 --> 00:05:57,335 In this case, we're going to use the left, 113 00:05:57,335 --> 00:06:02,103 down, and right cursor keys from the keyboard. 114 00:06:02,103 --> 00:06:05,709 So, I'm going to specify that red -- and remember 115 00:06:05,709 --> 00:06:08,301 in the Stroop task that the subjects are asked 116 00:06:08,301 --> 00:06:10,781 to report the color of the text rather than 117 00:06:10,781 --> 00:06:14,086 the word itself. So, when the color is red, I'm 118 00:06:14,086 --> 00:06:15,898 going to ask the subjects to press "left". 119 00:06:15,898 --> 00:06:19,152 That's the left cursor key. 120 00:06:19,152 --> 00:06:20,931 When it's green they should press "down". 121 00:06:20,931 --> 00:06:23,428 "Down" again. 122 00:06:23,428 --> 00:06:26,351 When the color's blue they should press "right". 123 00:06:26,351 --> 00:06:28,294 "Right". 124 00:06:28,294 --> 00:06:31,965 And now I've got red again, so they should 125 00:06:31,965 --> 00:06:32,973 press "left". 126 00:06:32,973 --> 00:06:35,811 Okay, that defines six different conditions 127 00:06:35,811 --> 00:06:38,616 for our experiment with four different parameters. 128 00:06:38,616 --> 00:06:41,480 Okay, let's save that file. 129 00:06:41,480 --> 00:06:47,119 I'm going to put it in the same folder as my 130 00:06:47,119 --> 00:06:49,467 experiment, although you don't have to. 131 00:06:49,467 --> 00:06:52,789 And I'm going to call it "conditions.xlsx". 132 00:06:52,789 --> 00:06:54,440 It's very important that you save it 133 00:06:54,440 --> 00:06:58,250 in the XLSX format. PsychoPy can't use the old 134 00:06:58,250 --> 00:07:02,468 XLS style spreadsheets. 135 00:07:02,468 --> 00:07:07,695 Click "Save" and we're done. 136 00:07:07,695 --> 00:07:11,758 So now we need to show PsychoPy where that file 137 00:07:11,758 --> 00:07:14,364 is, and how to use it during the trials. 138 00:07:14,364 --> 00:07:18,557 The way to do that is with the loop dialog. 139 00:07:18,557 --> 00:07:21,831 So, if I just click on that loop again, 140 00:07:21,831 --> 00:07:24,559 we'll get the properties back for the loop 141 00:07:24,559 --> 00:07:27,308 and there's a conditions file. If we browse, 142 00:07:27,308 --> 00:07:31,306 we can select our file that we've just created, 143 00:07:31,306 --> 00:07:37,468 open that, and it's told me that there are 144 00:07:37,468 --> 00:07:40,055 six conditions with four different parameters. 145 00:07:40,055 --> 00:07:41,618 The parameters are color, word, congruent 146 00:07:41,618 --> 00:07:43,452 and correct answer. 147 00:07:43,452 --> 00:07:47,662 Ok? If the file had been invalid in some way, 148 00:07:47,662 --> 00:07:49,665 maybe we had a space in one of our column 149 00:07:49,665 --> 00:07:52,212 headings, then we would get a warning here to 150 00:07:52,212 --> 00:07:54,216 say that we couldn't use that file or it 151 00:07:54,216 --> 00:07:56,612 wouldn't show us the parameters were there. 152 00:07:56,612 --> 00:07:59,880 Now we can select "OK". It's showing that we've 153 00:07:59,880 --> 00:08:05,294 got five times six random trials. 154 00:08:05,294 --> 00:08:09,788 So, five different repeats of six different conditions. 155 00:08:09,788 --> 00:08:14,637 Okay, so the conditions file is now being set 156 00:08:14,637 --> 00:08:17,054 here on each repeat through the loop, we use 157 00:08:17,054 --> 00:08:18,378 a different row. 158 00:08:18,378 --> 00:08:21,315 We still need to tell the stimulus about the 159 00:08:21,315 --> 00:08:24,035 parameters that it needs to use. 160 00:08:24,035 --> 00:08:26,312 We want the color of our stimulus to be set 161 00:08:26,312 --> 00:08:31,243 by that color parameter. Now, I've typed in 162 00:08:31,243 --> 00:08:35,336 "$colour" here, spelt with a "u" because that's 163 00:08:35,336 --> 00:08:38,028 how we spelt it in the Excel file. 164 00:08:38,028 --> 00:08:42,931 And that "$" is to tell PsychoPy "This isn't a 165 00:08:42,931 --> 00:08:45,845 literal value. It's a variable." 166 00:08:45,845 --> 00:08:47,767 Okay? So, it's going to go off and find a 167 00:08:47,767 --> 00:08:50,173 variable called "colour" and see what the current 168 00:08:50,173 --> 00:08:52,200 value of that variable is. 169 00:08:52,200 --> 00:08:54,164 It's going to be red or green or blue. 170 00:08:54,164 --> 00:08:58,678 I'm also going to set that to change on every repeat 171 00:08:58,678 --> 00:09:01,493 rather than being constant. 172 00:09:01,493 --> 00:09:03,436 Okay? We don't want the stimulus just to be 173 00:09:03,436 --> 00:09:07,220 fixed to one particular color for the entire experiment. 174 00:09:07,220 --> 00:09:11,238 Similarly, the text of this text stimulus should be 175 00:09:11,238 --> 00:09:15,916 the word that we've specified in the Excel file 176 00:09:15,916 --> 00:09:19,457 and it shouldn't be "word" it should be the variable 177 00:09:19,457 --> 00:09:22,394 "word" in order to go and fetch that variable 178 00:09:22,394 --> 00:09:24,506 which is going to be red or green or blue. 179 00:09:24,506 --> 00:09:29,034 And, again, we want that to change on every repeat 180 00:09:29,034 --> 00:09:31,091 of this routine. 181 00:09:31,091 --> 00:09:40,656 Okay. We also need to set the response to be 182 00:09:40,656 --> 00:09:44,970 based on the conditions. So I need to change 183 00:09:44,970 --> 00:09:47,391 the keys that are going to be allowed for 184 00:09:47,391 --> 00:09:49,464 the subject to respond with. We don't want them 185 00:09:49,464 --> 00:09:52,128 to use the "yes" or the "no". We want them to use 186 00:09:52,128 --> 00:09:57,230 "left", "right" and "down". So, notice that any keys 187 00:09:57,230 --> 00:10:00,581 I want to put here I separate by commas and 188 00:10:00,581 --> 00:10:05,026 I have to put inverted commas around the names 189 00:10:05,026 --> 00:10:07,494 of each of the keys. 190 00:10:07,494 --> 00:10:11,775 If I leave that blank -- the entire box -- then all keys 191 00:10:11,775 --> 00:10:14,809 will be available. Okay? So that allows the subject 192 00:10:14,809 --> 00:10:19,724 to press any key. I've also got "forceEndRoutine" 193 00:10:19,724 --> 00:10:22,765 checked here. We left the response to be 194 00:10:22,765 --> 00:10:26,222 infinite but as soon as they press any key, 195 00:10:26,222 --> 00:10:28,205 it will force the end of that trial. 196 00:10:28,205 --> 00:10:30,271 So that's a useful thing for us to do. 197 00:10:30,271 --> 00:10:32,813 We're also going to want to store correct. 198 00:10:32,813 --> 00:10:36,512 So, if I check that box, we have to tell PsychoPy 199 00:10:36,512 --> 00:10:39,030 what is the correct answer on this trial, 200 00:10:39,030 --> 00:10:43,857 and if you remember, that was stored as "corrAns". 201 00:10:43,857 --> 00:10:48,495 Again, we need to use "$corrAns" to specify 202 00:10:48,495 --> 00:10:52,550 the fact that this is a variable name not, 203 00:10:52,550 --> 00:10:54,919 it shouldn't be looking for a key called "corrAns" 204 00:10:54,919 --> 00:10:56,542 cause it will never find one. It's got to use 205 00:10:56,542 --> 00:11:00,997 the variable "corrAns". And that's us done. Okay. 206 00:11:00,997 --> 00:11:06,868 Save. Okay, we're pretty much there. 207 00:11:06,868 --> 00:11:09,619 That should be a working experiment, but we do also 208 00:11:09,619 --> 00:11:12,094 want to provide the subject with some instructions. 209 00:11:12,094 --> 00:11:15,383 I'm going to insert another routine into the flow. 210 00:11:15,383 --> 00:11:20,543 When I click that button it shows me either "new" 211 00:11:20,543 --> 00:11:24,298 or "trial". Let's select "new" and I'll call it 212 00:11:24,298 --> 00:11:31,254 "instructions"... if I can spell it. "Instructions". 213 00:11:31,254 --> 00:11:35,553 It asks where I want to insert the instructions. 214 00:11:35,553 --> 00:11:38,139 We don't want it to be here because that would 215 00:11:38,139 --> 00:11:40,016 repeat the instructions on every trial. 216 00:11:40,016 --> 00:11:43,980 Let's put it before the loop. And now we can click 217 00:11:43,980 --> 00:11:48,576 on the instructions routine and we can edit that. 218 00:11:48,576 --> 00:11:52,340 So, we're going to want another text object. 219 00:11:52,340 --> 00:12:02,253 We're going to call that, say, "instrText", 220 00:12:02,253 --> 00:12:05,829 start at time zero. Duration, we'll make it infinite. 221 00:12:05,829 --> 00:12:11,737 Color white, that's fine. And we'll give it the text 222 00:12:11,737 --> 00:12:27,509 "Remember choose the color of the letters, 223 00:12:27,509 --> 00:12:33,696 ignoring the word: 224 00:12:33,696 --> 00:12:46,957 left = red, down = green, right = blue. 225 00:12:46,957 --> 00:12:49,035 Okay. 226 00:12:49,035 --> 00:12:54,680 Now because we've made that text last forever, 227 00:12:54,680 --> 00:12:56,465 we gave it an infinite duration, we need to make 228 00:12:56,465 --> 00:12:59,016 sure that the subject can get rid of them. 229 00:12:59,016 --> 00:13:05,412 So, we'll click on a keyboard, we'll allow any key, 230 00:13:05,412 --> 00:13:10,151 we'll force the end of the routine, and we won't 231 00:13:10,151 --> 00:13:12,890 bother storing anything. 232 00:13:12,890 --> 00:13:15,799 We make that last forever. 233 00:13:15,799 --> 00:13:18,192 Okay. 234 00:13:18,192 --> 00:13:23,540 If you do get that wrong, you should always be able 235 00:13:23,540 --> 00:13:25,855 to hit "escape" and you will still be able to quit 236 00:13:25,855 --> 00:13:27,442 the experiment without having to 237 00:13:27,442 --> 00:13:28,735 restart your computer. 238 00:13:28,735 --> 00:13:31,079 Okay, I'm going to save that again. 239 00:13:31,079 --> 00:13:32,589 I think we're done. 240 00:13:32,589 --> 00:13:37,067 Okay, let's just have a quick look at the 241 00:13:37,067 --> 00:13:39,364 Experiment Settings dialog box. 242 00:13:39,364 --> 00:13:42,300 In this dialog, you can control things like whether 243 00:13:42,300 --> 00:13:45,123 or not the mouse is visible during the experiment, 244 00:13:45,123 --> 00:13:48,133 the color of the background of the screen, 245 00:13:48,133 --> 00:13:51,420 whether or not it's in a window or in full screen, 246 00:13:51,420 --> 00:13:54,463 is it "screen 1" or "screen 2" if you've got 247 00:13:54,463 --> 00:13:57,029 multiple monitors, and what sort of data files 248 00:13:57,029 --> 00:13:59,560 you want to save out. So, lots of useful things there 249 00:13:59,560 --> 00:14:01,869 to control your experiment. 250 00:14:01,869 --> 00:14:05,355 Now, at this point we could construct a script. 251 00:14:05,355 --> 00:14:08,771 That'll allow you to go off and maybe learn a little 252 00:14:08,771 --> 00:14:15,104 bit about how Python works. It's about 220 lines 253 00:14:15,104 --> 00:14:18,279 long, this particular experiment. So, not too 254 00:14:18,279 --> 00:14:21,785 complicated a script. But we don't need to. 255 00:14:21,785 --> 00:14:24,826 We could actually go off and run our experiment 256 00:14:24,826 --> 00:14:26,926 by hitting the green man. 257 00:14:26,926 --> 00:14:31,149 Often takes a few seconds, especially the first time 258 00:14:31,149 --> 00:14:34,740 you run. So, be patient with that one. 259 00:14:34,740 --> 00:14:36,785 There we go. We've got a dialog box come up 260 00:14:36,785 --> 00:14:39,596 asking for the participant and the session number. 261 00:14:39,596 --> 00:14:42,103 That was also being controlled in the Experiment 262 00:14:42,103 --> 00:14:43,712 Settings dialog. 263 00:14:43,712 --> 00:14:45,359 I'm not actually going to run the experiment. 264 00:14:45,359 --> 00:14:47,964 I'll leave that to you. 265 00:14:47,964 --> 00:14:49,795 Okay. Have you found that useful? 266 00:14:49,795 --> 00:14:51,821 Check out the Demos menu for more ideas 267 00:14:51,821 --> 00:14:54,000 and I hope you enjoy using PsychoPy!