Build your first PsychoPy experiment (Stroop task)
-
0:01 - 0:03Hi. My name's John Pierce.
-
0:03 - 0:04I'm a lecturer at the University of Nottingham.
-
0:04 - 0:07I'm the inventor of PsychoPy.
-
0:07 - 0:09In this demo, I'll show you how to
-
0:09 - 0:10create a simple experiment in PsychoPy.
-
0:10 - 0:12We're going to use the Stroop effect.
-
0:12 - 0:15When you first start up PsychoPy,
-
0:15 - 0:17you'll find two windows come open:
-
0:17 - 0:20One is the builder view, which allows you to
-
0:20 - 0:22construct your experiments graphically.
-
0:22 - 0:25And the other is the coder view, which allows you to
-
0:25 - 0:28create your experiments using Python scripts
-
0:28 - 0:30if you prefer to write code directly.
-
0:30 - 0:33Today we're going to be using the builder view.
-
0:33 - 0:37The builder view has three panels.
-
0:37 - 0:41It's got components. It's got one or more routines.
-
0:41 - 0:43Here we've got a single routine called the "trial".
-
0:43 - 0:46And it's got a flow which allows you to
-
0:46 - 0:52combine multiple routines together.
-
0:52 - 0:54In the case of the Stroop task, we'll need a
-
0:54 - 0:56a text object as part of our trial
-
0:56 - 0:58because we need to present a word to the subjects.
-
0:58 - 1:01So, let's create a text object.
-
1:01 - 1:04We'll call it "target". We'll have it start at
-
1:04 - 1:06maybe naught point five seconds,
-
1:06 - 1:09and it will last for five seconds.
-
1:09 - 1:12Notice that each of these parameters,
-
1:12 - 1:14as I hover my mouse over them, it gives me a tip to
-
1:14 - 1:18inform me about what I would be expected to include.
-
1:18 - 1:21There's also a help button. If I click on that,
-
1:21 - 1:24I'll go to the PsychoPy web site where it will tell me
-
1:24 - 1:27more detailed information about how to use
-
1:27 - 1:30this particular component.
-
1:30 - 1:33For now, we're not going to set color and the text
-
1:33 - 1:37of this text object. We'll come back to that
-
1:37 - 1:39later on.
-
1:39 - 1:43Having hit "OK", we can see the text object
-
1:43 - 1:46appearing in our routine and if we want to edit
-
1:46 - 1:48that, we can click on the icon again and we
-
1:48 - 1:51can get back and change our stimulus.
-
1:51 - 1:54Maybe we want it to be for four seconds, instead of for five.
-
1:54 - 1:57So it's now changed that representation.
-
1:57 - 2:01We also, for the Stroop task, need for the
-
2:01 - 2:04subjects to respond. So let's add a keyboard
-
2:04 - 2:10to this routine. We'll call it "response".
-
2:10 - 2:13We'll also start that at naught point five seconds.
-
2:13 - 2:15We don't want subjects to respond before
-
2:15 - 2:17the target was presented.
-
2:17 - 2:21I'm going to set this to have an infinite duration.
-
2:21 - 2:24If we set that to be blank, then the keyboard
-
2:24 - 2:27will be available forever.
-
2:27 - 2:30We're going to leave the allowed keys for now.
-
2:30 - 2:32I'll come back and change those later on,
-
2:32 - 2:34once we've set up our trials.
-
2:34 - 2:41OK, now we that the response is going to
-
2:41 - 2:43last forever.
-
2:43 - 2:47So, that's roughly what one trial is going to look like
-
2:47 - 2:50in the Stroop task. But we need to run more
-
2:50 - 2:52than one trial and right now we've got that
-
2:52 - 2:54routine appearing just once on our flow.
-
2:54 - 2:58Let's insert a loop around the trial,
-
2:58 - 3:00so that we can repeat it.
-
3:00 - 3:03If I click on "Insert loop" just once,
-
3:03 - 3:05and select, again with a single click,
-
3:05 - 3:09where we want our loop to start and stop.
-
3:09 - 3:13It brings up a dialog box, asking me
-
3:13 - 3:15what do I want to call this loop.
-
3:15 - 3:16We'll call it "trials". That's fine.
-
3:16 - 3:21Should it be random or sequential in choosing the next condition?
-
3:21 - 3:23Random is fine.
-
3:23 - 3:26We'll have five repeats, and we need to
-
3:26 - 3:28go and specify our conditions file.
-
3:28 - 3:30Now, you'll notice here it's asking for a trial
-
3:30 - 3:34a file that's CSV or XLSX. We need to go off
-
3:34 - 3:36to Excel in order to create our file.
-
3:36 - 3:40And click "OK". You'll see it insert the
-
3:40 - 3:43loop around the trial.
-
3:43 - 3:45Let's go and save that experiment now,
-
3:45 - 3:48so that we don't lose it.
-
3:48 - 3:54Save. I'm going to create a new folder on
-
3:54 - 4:01my desktop called "Stroop" and maybe I'll
-
4:01 - 4:05call the file "Stroop Experiment".
-
4:05 - 4:09Okay.
-
4:09 - 4:14The easiest way to define the conditions for
-
4:14 - 4:19your experiment is to use a spreadsheet package
-
4:19 - 4:20like Excel.
-
4:20 - 4:22We can create a number of parameters for
-
4:22 - 4:25our experiment, such as the word that we're
-
4:25 - 4:28going to present, or the color that it will
-
4:28 - 4:31be presented in, and we can create a number
-
4:31 - 4:34of different conditions. We specify one on each row.
-
4:34 - 4:38So, for the Stroop task, we might use the word "red"
-
4:38 - 4:44written in red. We might have the word "red" written
-
4:44 - 4:48in green. We might have the word "green"
-
4:48 - 4:51written in green, etc.
-
4:51 - 5:04"Green" in blue. "Blue" blue. "Blue" and red.
-
5:04 - 5:08I'm going to keep track of whether or not
-
5:08 - 5:10those are congruent. We don't really need to do this.
-
5:10 - 5:13We could always work it out later, but it's
-
5:13 - 5:16kind of convenient to have that stored as well.
-
5:16 - 5:18So, congruent and I'm going to say "1";
-
5:18 - 5:21that means "true"; and "0" for "false".
-
5:21 - 5:25That's just going to help us later on.
-
5:25 - 5:28Now we also need to specify what's the
-
5:28 - 5:31correct answer, cause PsychoPy will want to know
-
5:31 - 5:34whether or not the subject got it right or wrong.
-
5:34 - 5:40I'm going to call that "corrAns".
-
5:40 - 5:44These parameters can't use any punctuation
-
5:44 - 5:48or spaces in their names. So, I'm going to
-
5:48 - 5:51take away the space and give it a capital letter
-
5:51 - 5:54for, uh, to specify the correct answer.
-
5:54 - 5:57In this case, we're going to use the left,
-
5:57 - 6:02down, and right cursor keys from the keyboard.
-
6:02 - 6:06So, I'm going to specify that red -- and remember
-
6:06 - 6:08in the Stroop task that the subjects are asked
-
6:08 - 6:11to report the color of the text rather than
-
6:11 - 6:14the word itself. So, when the color is red, I'm
-
6:14 - 6:16going to ask the subjects to press "left".
-
6:16 - 6:19That's the left cursor key.
-
6:19 - 6:21When it's green they should press "down".
-
6:21 - 6:23"Down" again.
-
6:23 - 6:26When the color's blue they should press "right".
-
6:26 - 6:28"Right".
-
6:28 - 6:32And now I've got red again, so they should
-
6:32 - 6:33press "left".
-
6:33 - 6:36Okay, that defines six different conditions
-
6:36 - 6:39for our experiment with four different parameters.
-
6:39 - 6:41Okay, let's save that file.
-
6:41 - 6:47I'm going to put it in the same folder as my
-
6:47 - 6:49experiment, although you don't have to.
-
6:49 - 6:53And I'm going to call it "conditions.xlsx".
-
6:53 - 6:54It's very important that you save it
-
6:54 - 6:58in the XLSX format. PsychoPy can't use the old
-
6:58 - 7:02XLS style spreadsheets.
-
7:02 - 7:08Click "Save" and we're done.
-
7:08 - 7:12So now we need to show PsychoPy where that file
-
7:12 - 7:14is, and how to use it during the trials.
-
7:14 - 7:19The way to do that is with the loop dialog.
-
7:19 - 7:22So, if I just click on that loop again,
-
7:22 - 7:25we'll get the properties back for the loop
-
7:25 - 7:27and there's a conditions file. If we browse,
-
7:27 - 7:31we can select our file that we've just created,
-
7:31 - 7:37open that, and it's told me that there are
-
7:37 - 7:40six conditions with four different parameters.
-
7:40 - 7:42The parameters are color, word, congruent
-
7:42 - 7:43and correct answer.
-
7:43 - 7:48Ok? If the file had been invalid in some way,
-
7:48 - 7:50maybe we had a space in one of our column
-
7:50 - 7:52headings, then we would get a warning here to
-
7:52 - 7:54say that we couldn't use that file or it
-
7:54 - 7:57wouldn't show us the parameters were there.
-
7:57 - 8:00Now we can select "OK". It's showing that we've
-
8:00 - 8:05got five times six random trials.
-
8:05 - 8:10So, five different repeats of six different conditions.
-
8:10 - 8:15Okay, so the conditions file is now being set
-
8:15 - 8:17here on each repeat through the loop, we use
-
8:17 - 8:18a different row.
-
8:18 - 8:21We still need to tell the stimulus about the
-
8:21 - 8:24parameters that it needs to use.
-
8:24 - 8:26We want the color of our stimulus to be set
-
8:26 - 8:31by that color parameter. Now, I've typed in
-
8:31 - 8:35"$colour" here, spelt with a "u" because that's
-
8:35 - 8:38how we spelt it in the Excel file.
-
8:38 - 8:43And that "$" is to tell PsychoPy "This isn't a
-
8:43 - 8:46literal value. It's a variable."
-
8:46 - 8:48Okay? So, it's going to go off and find a
-
8:48 - 8:50variable called "colour" and see what the current
-
8:50 - 8:52value of that variable is.
-
8:52 - 8:54It's going to be red or green or blue.
-
8:54 - 8:59I'm also going to set that to change on every repeat
-
8:59 - 9:01rather than being constant.
-
9:01 - 9:03Okay? We don't want the stimulus just to be
-
9:03 - 9:07fixed to one particular color for the entire experiment.
-
9:07 - 9:11Similarly, the text of this text stimulus should be
-
9:11 - 9:16the word that we've specified in the Excel file
-
9:16 - 9:19and it shouldn't be "word" it should be the variable
-
9:19 - 9:22"word" in order to go and fetch that variable
-
9:22 - 9:25which is going to be red or green or blue.
-
9:25 - 9:29And, again, we want that to change on every repeat
-
9:29 - 9:31of this routine.
-
9:31 - 9:41Okay. We also need to set the response to be
-
9:41 - 9:45based on the conditions. So I need to change
-
9:45 - 9:47the keys that are going to be allowed for
-
9:47 - 9:49the subject to respond with. We don't want them
-
9:49 - 9:52to use the "yes" or the "no". We want them to use
-
9:52 - 9:57"left", "right" and "down". So, notice that any keys
-
9:57 - 10:01I want to put here I separate by commas and
-
10:01 - 10:05I have to put inverted commas around the names
-
10:05 - 10:07of each of the keys.
-
10:07 - 10:12If I leave that blank -- the entire box -- then all keys
-
10:12 - 10:15will be available. Okay? So that allows the subject
-
10:15 - 10:20to press any key. I've also got "forceEndRoutine"
-
10:20 - 10:23checked here. We left the response to be
-
10:23 - 10:26infinite but as soon as they press any key,
-
10:26 - 10:28it will force the end of that trial.
-
10:28 - 10:30So that's a useful thing for us to do.
-
10:30 - 10:33We're also going to want to store correct.
-
10:33 - 10:37So, if I check that box, we have to tell PsychoPy
-
10:37 - 10:39what is the correct answer on this trial,
-
10:39 - 10:44and if you remember, that was stored as "corrAns".
-
10:44 - 10:48Again, we need to use "$corrAns" to specify
-
10:48 - 10:53the fact that this is a variable name not,
-
10:53 - 10:55it shouldn't be looking for a key called "corrAns"
-
10:55 - 10:57cause it will never find one. It's got to use
-
10:57 - 11:01the variable "corrAns". And that's us done. Okay.
-
11:01 - 11:07Save. Okay, we're pretty much there.
-
11:07 - 11:10That should be a working experiment, but we do also
-
11:10 - 11:12want to provide the subject with some instructions.
-
11:12 - 11:15I'm going to insert another routine into the flow.
-
11:15 - 11:21When I click that button it shows me either "new"
-
11:21 - 11:24or "trial". Let's select "new" and I'll call it
-
11:24 - 11:31"instructions"... if I can spell it. "Instructions".
-
11:31 - 11:36It asks where I want to insert the instructions.
-
11:36 - 11:38We don't want it to be here because that would
-
11:38 - 11:40repeat the instructions on every trial.
-
11:40 - 11:44Let's put it before the loop. And now we can click
-
11:44 - 11:49on the instructions routine and we can edit that.
-
11:49 - 11:52So, we're going to want another text object.
-
11:52 - 12:02We're going to call that, say, "instrText",
-
12:02 - 12:06start at time zero. Duration, we'll make it infinite.
-
12:06 - 12:12Color white, that's fine. And we'll give it the text
-
12:12 - 12:28"Remember choose the color of the letters,
-
12:28 - 12:34ignoring the word:
-
12:34 - 12:47left = red, down = green, right = blue.
-
12:47 - 12:49Okay.
-
12:49 - 12:55Now because we've made that text last forever,
-
12:55 - 12:56we gave it an infinite duration, we need to make
-
12:56 - 12:59sure that the subject can get rid of them.
-
12:59 - 13:05So, we'll click on a keyboard, we'll allow any key,
-
13:05 - 13:10we'll force the end of the routine, and we won't
-
13:10 - 13:13bother storing anything.
-
13:13 - 13:16We make that last forever.
-
13:16 - 13:18Okay.
-
13:18 - 13:24If you do get that wrong, you should always be able
-
13:24 - 13:26to hit "escape" and you will still be able to quit
-
13:26 - 13:27the experiment without having to
-
13:27 - 13:29restart your computer.
-
13:29 - 13:31Okay, I'm going to save that again.
-
13:31 - 13:33I think we're done.
-
13:33 - 13:37Okay, let's just have a quick look at the
-
13:37 - 13:39Experiment Settings dialog box.
-
13:39 - 13:42In this dialog, you can control things like whether
-
13:42 - 13:45or not the mouse is visible during the experiment,
-
13:45 - 13:48the color of the background of the screen,
-
13:48 - 13:51whether or not it's in a window or in full screen,
-
13:51 - 13:54is it "screen 1" or "screen 2" if you've got
-
13:54 - 13:57multiple monitors, and what sort of data files
-
13:57 - 14:00you want to save out. So, lots of useful things there
-
14:00 - 14:02to control your experiment.
-
14:02 - 14:05Now, at this point we could construct a script.
-
14:05 - 14:09That'll allow you to go off and maybe learn a little
-
14:09 - 14:15bit about how Python works. It's about 220 lines
-
14:15 - 14:18long, this particular experiment. So, not too
-
14:18 - 14:22complicated a script. But we don't need to.
-
14:22 - 14:25We could actually go off and run our experiment
-
14:25 - 14:27by hitting the green man.
-
14:27 - 14:31Often takes a few seconds, especially the first time
-
14:31 - 14:35you run. So, be patient with that one.
-
14:35 - 14:37There we go. We've got a dialog box come up
-
14:37 - 14:40asking for the participant and the session number.
-
14:40 - 14:42That was also being controlled in the Experiment
-
14:42 - 14:44Settings dialog.
-
14:44 - 14:45I'm not actually going to run the experiment.
-
14:45 - 14:48I'll leave that to you.
-
14:48 - 14:50Okay. Have you found that useful?
-
14:50 - 14:52Check out the Demos menu for more ideas
-
14:52 - 14:54and I hope you enjoy using PsychoPy!
- Title:
- Build your first PsychoPy experiment (Stroop task)
- Description:
-
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!
- Video Language:
- English, British
- Duration:
- 14:54
Kevin Cole edited English subtitles for Build your first PsychoPy experiment (Stroop task) | ||
Kevin Cole edited English subtitles for Build your first PsychoPy experiment (Stroop task) | ||
Kevin Cole edited English subtitles for Build your first PsychoPy experiment (Stroop task) | ||
Kevin Cole added a translation |