Return to Video

Build your first PsychoPy experiment (Stroop task)

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

more » « less
Video Language:
English, British
Duration:
14:54

English subtitles

Revisions