Affect Misattribution Procedure (AMP) experiment for oTree
This repository contains an application for oTree (Chen et al. 2016) which implements the Affect Misattribution Procedure (AMP) experiment (Payne et al. 2005, Payne & Lundberg 2014, Teige-Mocigemba et al. 2017).
Images of targets (Chinese characters) in directory
_static/amp/targets were published by Keith Payne at http://bkpayne.web.unc.edu/research-materials/.
Screenshot of a trial:
Features and limitations
- precise timing of prime and target exposures in milliseconds
- prime and target images are pre-loaded before first display to prevent download delay
- 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
- easily adjustable (see configuration)
- 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
Prime and target images
For your own experiment, you probably want to exchange the prime images (the repository contains example images of cats and dogs) and optionally the target images. Both are located in
The repository comes with example images for two prime classes
prime_b inside the
primes folder. The images are automatically loaded if you put them there and randomly assigned to the target classes. The number of images per prime class should be the same.
As explained before, the images for the targets are Chinese characters obtained from http://bkpayne.web.unc.edu/research-materials/ and divided into positive (
pos folder) and negative (
neg folder) classes. You may replace those images – you should only make sure that the number of images per target class is the same. The number of images determines the number of trials that are run per block.
Further configuration via
Constants class in
amp/models.py contains further configuration settings such as the number of blocks (
num_rounds) and the display timings that determine for how long the prime and target image are shown.
Code structure and page sequence
Trial class is defined in
amp/models.py that stores information for each trial per player such as displayed prime / target and participant's response. The trials are set up in
creating_session() in class
Subsession where the prime and target images are detected in the respective folders and random assignment of primes and targets takes place (see
Pages and templates
The page sequence consists of four classes in
AMPPracticePage is derived from
AMPPage and uses the same template (
AMPPage.html) but sets
True. On the practice page, the participant can try out the experiment process without recording any measurments. Primes and targets for the practice page are loaded from the respective folders with
_practice suffix in
_static/amp/. The real 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
amp/tests.py and can be run via
otree test amp.
Apache License 2.0. See LICENSE file.