The Seven-parameter Diffusion Model: an Implementation in Stan for Bayesian Analyses

Franziska Henrich, Raphael Hartmann, Valentin Pratz, Andreas Voß, Karl Christoph KlauerBehavior 2023

Abstract

Diffusion models have been widely used to obtain information about cognitive processes from the analysis of responses and response-time data in two-alternative forced-choice tasks. We present an implementation of the seven-parameter diffusion model, incorporating inter-trial variabilities in drift rate, non-decision time, and relative starting point, in the probabilistic programming language Stan. Stan is a free, open-source software that gives the user much flexibility in defining model properties such as the choice of priors and the model structure in a Bayesian framework. We explain the implementation of the new function and how it is used in Stan. We then evaluate its performance in a simulation study that addresses both parameter recovery and simulation-based calibration. The recovery study shows generally good recovery of the model parameters in line with previous findings. The simulation-based calibration study validates the Bayesian algorithm as implemented in Stan.

Introduction

In cognitive psychology, the Diffusion Model (DM) serves as the gold standard for understanding two-alternative forced-choice (2AFC) tasks. Whether a participant is deciding if a string of letters is a word or a non-word, or determining the direction of moving dots, the DM provides a mathematical framework to decompose observed response times and accuracy into latent cognitive processes.

While basic four-parameter models are common, they often fail to account for the nuances of human performance, such as the presence of fast or slow errors. To address this, the "full" seven-parameter Ratcliff Diffusion Model introduces inter-trial variabilities. However, these additional parameters make the model notoriously difficult to estimate. This paper introduces a robust implementation of the full seven-parameter DM within the Stan probabilistic programming ecosystem, providing researchers with a fast, flexible, and mathematically rigorous tool for Bayesian analysis.

The Diffusion Model Framework

The basic DM describes decision-making as a process of evidence accumulation over time. Evidence starts at a certain point and drifts toward one of two boundaries. Once a boundary is crossed, a response is initiated.

The evidence accumulation process in a diffusion model, showing the path toward Response A or B over time.

The core parameters include:

  • Boundary separation ($a$): Reflects the degree of caution; wider boundaries require more evidence.
  • Drift rate ($v$): Represents the quality of evidence or the speed of information processing.
  • Starting point ($w$): Indicates a-priori bias toward one of the responses.
  • Non-decision time ($t_0$): Accounts for time spent on motor execution and sensory encoding.

The "full" model adds three inter-trial variability parameters ($s_v, s_w, s_{t_0}$) to account for fluctuations in attention or motor preparation across different trials, allowing the model to capture complex response distributions that simpler versions miss.

Implementation in Stan

The primary contribution of this work is the native Stan function wiener_full_lpdf(). Estimating the seven-parameter model is computationally intensive because it involves complex integrals. To make this practical for Stan’s No-U-Turn Sampler (NUTS), the authors implemented analytical partial derivatives (gradients) directly into the C++ backend.

Graphical model representation of the seven-parameter diffusion model implementation, showing the dependencies between core parameters and inter-trial variabilities.

By hard-coding these gradients rather than relying on Stan's default automatic differentiation, the authors achieved significant gains in speed and numerical stability. This modular implementation allows researchers to embed the DM into complex hierarchical structures while maintaining the freedom to define custom prior distributions—a flexibility often lacking in specialized packages like HDDM.

Validation and Performance

The authors validated the implementation through two rigorous simulation studies:

  1. Parameter Recovery Study: Using 4,000 synthetic datasets, the study tested the model's ability to recover true parameter values. For datasets with 500 trials, the correlation between true and estimated values was exceptionally high ($r > .97$) for core parameters like $a, v, t_0,$ and $w$. However, the study confirmed that inter-trial variability in the starting point ($s_w$) remains the most difficult parameter to estimate, requiring larger trial counts for reliable recovery.
  2. Simulation-Based Calibration (SBC): This "sanity check" for Bayesian algorithms confirmed that the implementation is free of systematic bias. The resulting rank statistics followed a uniform distribution, indicating that the posterior distributions accurately reflect the underlying uncertainty.

In terms of efficiency, the use of Stan’s reduce_sum for parallelization allows a 500-trial model to be fitted in approximately 20 to 44 minutes on modern hardware, making it a viable tool for standard research workflows.

Conclusion and Future Work

This implementation brings the full power of the Ratcliff Diffusion Model to the Stan community. While the study highlights that at least 500 trials are recommended to reliably estimate variability parameters, the tool's flexibility allows researchers to "turn off" these parameters for smaller datasets.

Future developments may include integrating outlier-resistant likelihoods to handle "contaminant" data, such as accidental button presses. For now, this work provides a mathematically rigorous foundation for the next generation of Bayesian cognitive modeling.

Summary updated

BibTeX
@inproceedings{henrich2023seven,
  author = {Franziska Henrich and Raphael Hartmann and Valentin Pratz and Andreas Voß and Karl Christoph Klauer},
  title = {{The Seven-parameter Diffusion Model: an Implementation in Stan for Bayesian Analyses}},
  booktitle = {Behavior},
  year = {2023},
  doi = {10.3758/s13428-023-02179-1},
}
Figure