Skip to content

WZBSocialScienceCenter/otree_iat

Repository files navigation

Implicit Association Test (IAT) experiment for oTree

March 2021, Markus Konrad markus.konrad@wzb.eu / post@mkonrad.net / Berlin Social Science Center

This project is currently not maintained.

Introduction

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

Optionally 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
  • 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
  • optional: live view of measurements during experiment in oTree's data view

Requirements

  • tested with Python 3.7 and Python 3.8
  • tested with otree 3.3.0 to otree 3.3.11

oTree IAT may work with higher versions than specified here, but this is untested.

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

If you want to see live view of measurements during the experiment in the "data" view of oTree's admin panel, you additional need to install otreeutils version 0.10.0 or newer: pip install otreeutils[admin].

If you want to use oTree IAT with an older version of oTree, you may try a previous release as listed under Releases on the right side. To know which version of oTree IAT works with which version of oTree, see the Changes section below.

Configuration

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 STIMULI, STIMULI_LABELS and BLOCKS.

Further configuration via Constants

The 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

Models

A custom 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 iat/pages.py:

  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

You can export the data from the "Data" page (https://<yourserver>/export) via the iat (custom) links. If you have otreeutils installed, you can also use the data_exporter.py script by executing python data_exporter.py my_data.json in the terminal, which will store all collected data in JSON format 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.

Tests

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

Testing multiple combinations of Python and oTree versions is done using tox. You can install the package tox via pip and then run tox on the command line.

Code changes

2021-03-03: v1.1.1 (oTree 3.3.x)

  • dependency to otreeutils is now optional (brings back session data live view via otreeutils 0.10.0)

2021-02-18: v1.1.0 (oTree 3.3.x)

  • added compatibility with oTree 3.3.x (PR #3 – thanks to Christoph Semken)
  • added tox integration for testing multiple Python/oTree versions

2019-11-05: v1.0.0 (oTree 2.1.x)

  • initial release

Authors

License

Apache License 2.0. See LICENSE file.