Skip to content
Implicit Association Test (IAT) experiment for oTree
Python HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Implicit Association Test (IAT) experiment for oTree

November 2019, Markus Konrad / Berlin Social Science Center


This repository contains an application for oTree (Chen et al. 2016) which implements the Implicit Association Test (IAT) experiment (Greenwald et al. 1998).

Makes use of the otreeutils package (Konrad 2018).

Trial block introduction:

trial block intro

A trial:

a trial

Features and limitations

  • stimuli and trial blocks easily adjustable (see configuration)
  • precise measurement of responses in milliseconds
  • progress bar showing advancement of trials for each participant
  • each measurement is stored individually in the database
  • live view of measurements during experiment in oTree's data view
  • requires keyboard for responses but may be extended to work on mobile devices as well
  • results are transferred to server at the end of each round (each round or block consists of several trials), not after each trial


  • Python 3.5 or higher (tested with Python 3.6)
  • otree 2.1.41
  • otreeutils 0.9.1

You can install the exact requirements using pip: pip install -r requirements.txt


Stimuli and trial blocks

For your own experiment, you probably want to exchange the stimuli and adjust the trials. You can do so in iat/ by editing STIMULI, STIMULI_LABELS and BLOCKS.

Further configuration via Constants

The Constants class in iat/ contains further configuration settings such as the number of blocks (num_rounds) and the keys on the keyboard that are used for input.

Code structure and page sequence


A custom Trial class is defined in iat/ that stores information for each trial per player such as displayed stimulus and participant's response. The trials are set up in creating_session() in class Subsession where the stimuli are loaded depending on the block definition and their order is randomized.

Pages and templates

The page sequence consists of three classes in iat/

  1. Intro
  2. IATPage
  3. Outro

The test is then implemented in IATPage, especially in the JavaScript functions of the HTML template. The randomized Trial objects are loaded for the participant for the given round and passed to the template where they are displayed. During the test, the response times and keys are recorded and submitted when the next block is loaded or all blocks are finished. The submitted trial responses are handled and stored to the database in the method IATPage.before_next_page().

Data export

Since the measurements are stored using the custom data model Trials (see this blog post or Konrad 2018 for more on custom data models with oTree), the data is not exported automatically using oTree's data export page. However, two methods are provided to obtain the data in hierarchically structured JSON format:

  1. You can access the page https://<SERVER>/custom_export/ (e.g. http://localhost:8000/custom_export/ on a local development machine) which, after logging in, lets you download the data.
  2. You can use the script, e.g. by executing python my_data.json in the terminal, which will store the JSON data to my_data.json.

For later processing of the JSON data, you may use the jsonlite package for R or the built-in json module in Python.


Automated tests are implemented in iat/ and can be run via otree test iat.


Apache License 2.0. See LICENSE file.

You can’t perform that action at this time.