A lead researcher explaining the benefits of Cognition.run

Crafting Behavioral Economics Experiments with jsPsych and Cognition

Why behavioral economics runs well in a browser

Behavioral economics studies how people actually make decisions about money, time and risk, as opposed to how a perfectly rational agent would. Most of its core paradigms share a convenient property: they are sequences of choices between clearly described options, presented as text and buttons. They rarely depend on millisecond timing or precise visual control, which makes them among the easiest experiments to move online without losing anything that matters.

The standard paradigms

  • Ultimatum game (Güth, Schmittberger and Schwarze, 1982). A proposer splits a sum; a responder accepts or rejects, and rejection leaves both with nothing. Offers below roughly 20 to 30 percent are frequently rejected, contrary to the prediction that any positive offer should be accepted.
  • Dictator game. The same split, but the recipient cannot reject. Any giving at all is evidence of other-regarding preferences, and the amount given is sensitive to anonymity, framing and social distance.
  • Delay discounting. Choices between a smaller amount now and a larger amount later. The 27-item questionnaire of Kirby, Petry and Bickel (1999) estimates a discount rate k from a fixed set of choices; Rachlin and colleagues' work established the hyperbolic form of the discount function that these procedures assume.
  • Risk and loss aversion. Choices between gambles and sure amounts, following Kahneman and Tversky (1979). Loss aversion is usually estimated from the smallest gain a participant requires to accept a 50/50 gamble with a given loss.
  • Balloon Analogue Risk Task (BART) (Lejuez et al., 2002). Participants pump a virtual balloon to earn money per pump, with an unknown explosion point. The adjusted average number of pumps is a behavioral measure of risk taking.
  • Public goods game. Group members contribute to a shared pot that is multiplied and divided equally. Contributions typically start around half the endowment and decline over rounds unless punishment or communication is allowed.

Example: a delay discounting task in jsPsych 8

The following code presents a series of choices between a smaller immediate amount and a fixed larger amount at a delay. Each trial records both amounts, the delay and which option was chosen, which is everything you need to fit a discount function afterwards. The left/right position of the options is randomized on every trial to avoid a side bias.

const jsPsych = initJsPsych();

const later = 100;
const delays = [7, 30, 90, 180, 365];
const nowAmounts = [10, 25, 40, 55, 70, 85, 95];

const choices = [];
for (const delay of delays) {
  for (const now of nowAmounts) {
    choices.push({ now, delay });
  }
}

const choiceTrial = {
  type: jsPsychHtmlButtonResponse,
  stimulus: "<p>Which would you prefer?</p>",
  choices: () => {
    const now = jsPsych.evaluateTimelineVariable("now");
    const delay = jsPsych.evaluateTimelineVariable("delay");
    return [`$${now} today`, `$${later} in ${delay} days`];
  },
  data: {
    task: "delay_discounting",
    now_amount: jsPsych.timelineVariable("now"),
    later_amount: later,
    delay_days: jsPsych.timelineVariable("delay")
  },
  on_finish: (data) => {
    // response is 0 for the left button, 1 for the right button
    data.chose_later = data.response === 1;
  }
};

const timeline = [
  {
    type: jsPsychInstructions,
    pages: [
      "<p>You will see pairs of options. Click the one you would rather have.</p>" +
      "<p>One of your choices will be selected at random and paid as a bonus.</p>"
    ],
    show_clickable_nav: true
  },
  {
    timeline: [choiceTrial],
    timeline_variables: choices,
    randomize_order: true
  }
];

jsPsych.run(timeline);

Because choices is a function here, it uses jsPsych.evaluateTimelineVariable() (the jsPsych 8 form); the data object uses jsPsych.timelineVariable() directly, which works when passed as a parameter. If you want side randomization as well, store a later_on_right flag in data, swap the button labels accordingly, and compute chose_later from both values in on_finish. With 35 choices, the indifference point at each delay can be estimated as the midpoint between the largest immediate amount rejected and the smallest accepted, and a hyperbolic k fitted across delays.

Design considerations that matter online

Real incentives. Experimental economics has a strong norm against hypothetical payoffs, and for good reason: behavior in games changes when money is at stake. Online, the standard solution is to pay a base fee plus a bonus determined by one randomly selected trial. Prolific supports bonus payments per participant, and because Cognition records URL parameters such as PROLIFIC_PID as a column on every trial, computing each participant's bonus from the exported CSV is straightforward. See our guide on Prolific, SONA and MTurk integration.

Randomization and counterbalancing. Randomize trial order (as above), randomize which side each option appears on, and if you compare framings or endowments between participants, assign them to conditions in a balanced way. Cognition balances between-subject conditions on the server and exposes the assignment as window.CONDITION, so you can branch your timeline on it without writing your own allocation logic.

Partners and deception. Multi-player games are usually run online with simulated partners or with pre-recorded decisions from earlier participants. Economics journals generally prohibit deceiving participants, while psychology permits it with debriefing; decide which norm applies to your venue before you design the task, and describe the partner honestly in the consent text if you can. Cognition's consent page accepts markdown and sends participants who decline to a URL of your choosing.

Attention and comprehension. Include a comprehension check after the instructions (for example, "If you choose the right option, how much will you receive and when?") and record it in the data so you can exclude participants who failed it, according to criteria you set in advance.

Hosting the task

To run the example, create a free account, paste the code into the editor, select jsPsych 8.2.3, and copy the participant link into your Prolific study. Each choice is saved to the server the moment it is made, data can be exported as CSV or JSON, single-use links prevent repeat participation, and recruitment can be capped at a fixed number of participants. The free plan covers four tasks with sixty participants each, which is enough to pilot a discounting or dictator task before committing a budget to it. The documentation describes the data format and the conditions feature in detail.