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