Implicit Association Test (IAT) experiment for oTree
Trial block introduction:
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/models.py by editing
Further configuration via
Constants class in
iat/models.py 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
Trial class is defined in
iat/models.py 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
The test is then implemented in
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
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:
- You can access the page
http://localhost:8000/custom_export/on a local development machine) which, after logging in, lets you download the data.
- You can use the
data_exporter.pyscript, e.g. by executing
python data_exporter.py my_data.jsonin the terminal, which will store the JSON data to
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/tests.py and can be run via
otree test iat.
Apache License 2.0. See LICENSE file.