Chapter 16 Lab 6 exercise and formative PsychoPy assignment

16.1 Lab 6 exercise

In your view, the 2-letter version of the letter flanker task has a confound: congruent stimuli always consist of exactly the same letters, whereas incongruent stimuli consist of different letters. You wonder if the interference effect could be due to the fact that the row of identical letters in congruent trials speeds up letter recognition, and not the fact that in incongruent trials flanker and target map onto different responses.

You plan to investigate this question by creating a 4-letter version of the flanker task as a 4-letter version allows for congruent trials where flankers and target differ.

The four letters in your task and the correct responses are:

  • B and G: left arrow key
  • D and Q: right arrow key

For the purpose of defining correct responses in an input file, the names for the arrow keys are left and right.

Please create an experiment that fulfils the following criteria:

  • Congruent and incongruent trials should be equally frequent.
  • Congruent trials should not include strings of identical letters (e.g., BBBBB).
  • There should be 64 trials overall.
  • The input file should be repeated 4 times.
  • The letter presentation should begin 0.5 seconds after the start of the trial.
  • The presentation of the letters should end when a response key is pressed.
  • Trials should be presented in random order.
  • PsychoPy should write accuracy information to the output file.
  • Trial-wise congruency should also be coded in the output file.

Your stimuli should be:

  • 150 pixels high
  • White on black background
  • Presented in the centre of the screen

OMG! I don’t know where to start!

Start by opening my version of the flanker task the you previously downloaded (or re-download the task) and try to work out how this task works. Run it. Play around with it. Change things and see what happens. As mentioned in the previous lab, you can’t really break anything. If you change something and the task no longer works, simply download it again (or make a copy or the original version before you make changes to it).

Once you think you have a sufficient understanding of how the task works, try to adapt the two-letter version instead of creating a completely new experiment.

How do I set up the input file? (Hint 1)

The basic idea is to create all possible letter combinations that meet the criteria defined above.

I’ve read Hint 1, but I’m still stuck on the input file. (Hint 2)

You might be puzzled by the fact that you end up with fewer possible congruent stimuli (4) than incongruent stimuli (8). The solution is to simply duplicate the congruent stimuli, so you have eight congruent and incongruent stimuli.

Aaaarghhh!!! I’ve read Hint 1 and Hint 2, but I’m still stuck. (Hint 3)

These are your eight congruent stimuli:

BBGBB, BBGBB, GGBGG, GGBGG, DDQDD, DDQDD, QQDQQ, QQDQQ

Why are these stimuli congruent although the letters differ? Think back to the Stroop task explained in Chapter 9: Why is the stimulus RED congruent? The word “RED” and the colour red are obviously different. Yet the stimulus is congruent. It is congruent because the relevant dimension (the colour) and the irrelevant dimension (the word) map onto the same response (“red”). The same is true for your congruent flanker trials: “B” and “G” are associated with the same response (“left arrow key”).

These are your eight incongruent stimuli:

DDBDD, QQBQQ, DDGDD, QQGQQ, BBDBB, GGDGG, BBQBB, GGQGG

You now have 16 “conditions” in your input file. Thus, you need four repetitions to achieve 64 trials overall.

You can watch a video of the solution here:

16.2 Formative PsychoPy assignment

The instructions for the formative PsychoPy assignment are available from Tuesday, 16 November at 9am.30 Please note that the instructions also explain how exactly the assignment needs to be submitted. Please submit your experiment using this link by Wednesday, 24 November at 5pm.

This is a formative exercise that will not contribute to your overall mark. Formative assignments not submitted by the deadline incur no penalty. While formative, we would highly recommend that you complete the assignment. The next assignment will be the summative PsychoPy assignment. Successfully completing the formative assignment will help you to do well on the summative assignment. In fact, in previous years we found that students who submitted a formative PsychoPy assignment performed significantly better on the summative assignment compared to those students who did not submit a formative PsychoPy assignment.31 Please do submit your formative PsychoPy assignment even if it is not quite working or doesn’t run at all. This will give us a better idea of the issues you encountered when creating the experiment.

16.2.1 Effect of submitting the formative PsychoPy assignment

Let’s compare the summative PsychoPy results for those who did and did not submit the formative PsychoPy assignment in 2021. As a first step, let’s plot the distributions using a raincloud plot.

library(tidyverse)
library(ggplot2)
library(ggdist)

# read csv file
data <- read_csv("./assets/formative_YN_comparison_HHG.csv")

# disregard all students who did not submit the summative assignment
data <- filter(data, Mark > 0)

data %>%
  ggplot(aes(x = Submitted, y = Mark, fill = Submitted)) +
  ggdist::stat_halfeye(adjust = 0.7, .width = 0, point_colour = NA, justification = -0.25, alpha = 0.6, scale = 0.4) +
  geom_boxplot(width = .12, outlier.colour = NA) +
  ggdist::stat_dots(side = "left", justification = 1.15) +
  theme_minimal() +
  scale_color_brewer(palette="Accent") +  # change outline colours
  scale_fill_brewer(palette="Accent") +   # change fill colours
  scale_x_discrete(limits = c("y", "n")) +
  scale_y_continuous(breaks = seq(from = 0, to = 100, by = 10)) +  # x axis tick labels every 10
  theme(legend.position = "none") +
  coord_flip()  # flip x and y

Note how students who submitted the formative PsychoPy assignment did substantially better overall.

Let’s compute some descriptive statistics.

## data$Submitted: n
##       Mark        Submitted        
##  Min.   : 2.00   Length:121        
##  1st Qu.:35.00   Class :character  
##  Median :57.00   Mode  :character  
##  Mean   :53.33                     
##  3rd Qu.:73.00                     
##  Max.   :95.00                     
## ------------------------------------------------------------ 
## data$Submitted: y
##       Mark        Submitted        
##  Min.   : 6.00   Length:246        
##  1st Qu.:60.00   Class :character  
##  Median :71.50   Mode  :character  
##  Mean   :68.41                     
##  3rd Qu.:82.00                     
##  Max.   :99.00

Note how the mean and median in the group who submitted the formative assignment are substantially higher. Also note that as students weren’t randomly assigned to a formative assignment group and a no formative assignment group this is not an experimental design and thus cannot be interpreted causally. However, it nevertheless shows that students who choose to submit a formative PsychoPy assignment are much more likely to do well on the summative assignment.

16.3 Lab 6 challenge exercise

Build a Posner cueing task. The Posner cueing task is a spatial attention task. Participants are asked to indicate the location of a target on the screen. In our example implementation, the target will be a red triangle which is presented on either the left side or the right side of the screen. If the triangle is on the left side, participants should press z key, if it is on the right, they should press the / key. Shortly before the target, a cue is presented. The cue is irrelevant for the task. In our example, the cue will be a colour change in one of three squares. Combining cue locations with target locations gives us three possible trial types (i.e., we’re manipulating what is referred to as trial validity):

Your trials should have the following trial structure and timing:

Participants should complete 24 trials overall. Trial types should be equally frequent. Apart from the relevant information about the stimuli, your input file should also include information about the correct response and the validity of the trial. Colours should be similar to ones shown in the figures above.

Use PsychoPy’s Polygon component to create the stimuli (found under Stimuli components). As always, there are multiple ways to implement a task. Think about what the easiest way to create this task is. It often helps to draw what you’re trying to achieve. For example, you could attempt to draw the components that you need in your trial as well as their respective timing.

Hint 1

Only look at this hint after you’ve thought about what the best way to implement the task is. Thinking about how to implement the task efficiently is just as important as actually implementing the task. Finding a good solution can save you a lot of time later.

In my view, the simplest solution would be to have a separate polygon component for the cue. This component needs be added below the other squares:

Adding it below the other squares means that it will drawn on the screen last (and thus on top of the other squares). For this component, the only thing that needs to change from trial to trial is the location. Everything else can be constant. The other three squares can be completely constant; i.e., nothing needs to change from trial to trial (and thus they don’t show up in the input file at all). In terms of stimuli, the only other thing that changes from trial to trial is the location of the target.

Hint 2: How do I get the stimuli to change locations from trial to trial?

In this experiment, cue and target position need to vary from trial to trial. Thus, you need two columns in your input file that indicate which position the cue and the target should have on each trial. As the stimuli never change their position on the y-axis, it is sufficient to vary the position on the x-axis. You could thus label the corresponding columns in your input file xPosCue and xPosTarget (or whatever helps you to remember what it is these columns do).

For your Polygon component for the cue, you would then use this in the Position field: (xPosCue, 0) (note that the Position property already has $-sign, so you don’t need to add this here)

16.4 Quick survey


  1. Note that this is a few days earlier than announced in the appendix. We thought it might be helpful to have a few extra days for this assignment. However, please note that we will not be answering questions about the formative PsychoPy assignment that go beyond those described as acceptable in the task instructions. We will be happy to answer any questions you have about the exercise for Lab 6 though.↩︎

  2. Note that this is a great example of self-selection though! Students were not randomly allocated to conditions, but decided themselves whether or not to complete the formative PsychoPy assignment. That said, we probably don’t need to run a study to convince you that practising using PsychoPy will help when it comes to creating the summative PsychoPy experiment. In addition, about a quarter of the questions in the exam in January will be PsychoPy questions.↩︎