Chapter 15 Using information from input files
Information in an input file can have different purposes. You can use this information to:
- Define a stimulus
- Determine if a participant responded correctly
- Add additional information to the PsychoPy output file (we will discuss output files in more detail in two weeks)
Let’s look at these use cases in turn.
15.1 Defining a stimulus
How does PsychoPy know that what you called stim
in your input file should be used to determine which stimulus is presented? For this, we need variables. Think of a variable simply as something that can change from one trial to the next. Variables have names and values. A simple example could be \(x = 5\). Here, the variable has the name \(x\) and the value \(5\). We can also say that we assigned the value \(5\) to the variable \(x\).
To understand how input files and stimulus components can be linked, you need to know that the column headers in input files can be used as variable names in PsychoPy. The orange arrow in Fig. 15.1 illustrates how the column called stim
in our input file is linked with our Text component.
Note that the variable name in PsychoPy and the header in the input file need to match exactly. For example, stim
in PsychoPy and Stim
in the input file will not work! A frequent error that can be really hard to spot is adding a space after the column header in Excel, e.g., stim
. Many a student has been driven to desperation over this!
There are two further important characteristics in this text component:
- Note the
$
sign beforestim
(purple arrow in Fig. 15.1). This tells PsychoPy that whatever follows the$
should not be interpreted as text (but, in this case, as a variable name). - Note that “Text” is set to
set every repeat
(red arrow in Fig. 15.1). This means that the value of the variable will be updated on every trial.
Note that sometimes you might need more than one column in the input file to define a stimulus. For example, to define the Stroop stimulus RED, you need to get information about the word as well as the colour from the input file. Thus, your input file needs separate columns for defining word and colour. The same is true when you would like to change, say, the stimulus and its location from trial to trial.
Also note that sometimes it is not necessary to add the $
sign before a variable name. This is the case when the field name already includes a $
sign. For example, this is the case for the position property:
You need three things to ensure that PsychoPy uses the information from the input file to update the stimulus information on each trial:
- Column headers in Excel and variable names in PsychoPy must match exactly.
- You must add a
$
sign before the variable name (if the$
is not already there). - The component must be set to
set every repeat
.
15.2 Determining a correct response
Information in the input file can also be used to determine if the participant gave a correct response. Fig. 15.2 shows again the Keyboard component from Section 12.3. The orange arrow illustrates how the column called corrAns
in our input file is linked with our Keyboard component. Note that you need to tick “Store correct” for the field “Correct answer” to appear. Also note that the “Allowed keys” can be constant as these are the same on every trial.
If “Store correct” is ticked and a variable name for “Correct answer” is provided, PsychoPy will write information about the accuracy of the response on each trial to the output file it produces. However, this information is not just useful for the output file. It can also be used to give participants online feedback about their performance. This is something we will have a closer look at next week.
15.3 Adding additional information to the output file
What happens to information in the input file that is not used in one of the components? For example, the information about the congruency? Like the other information in the input file, it will automatically be written to the output file PsychoPy creates. When you analyse your data, it will be helpful to have this information readily available.