stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
756 stars 188 forks source link

Adding 5-Parameter Drift Diffusion Model (DDM) PDF and CDF to Stan Math #2584

Open kendalfoster opened 3 years ago

kendalfoster commented 3 years ago

Description

Ratcliff's Diffusion Decision Model (DDM) is a popular model for jointly modelling binary responses and their associated response times. The DDM exists in several parameterizations, and currently Stan Math contains the PDF of the 4-parameter variant (i.e., the parameters for threshold separation, non-decision time, relative starting point of the diffusion process, and drift rate of the diffusion process) via the function wiener_lpdf(). This issue proposes to add the 5-parameter variant of the DDM (i.e., including the parameter for inter-trial variability in the drift rate) to Stan Math by adding the new functions ddm_lpdf() and ddm_lcdf().

I am submitting a pull request to add these two new functions (ddm_lpdf() and ddm_lcdf()). Both functions accept the following parameters: response time, response, threshold separation, drift rate, non-decision time, relative starting point, inter-trial variability in the drift rate. This pull request has been discussed in this Discourse thread.

Example

An example call to the (logged) PDF is ddm_lpdf(1, 1, 1, -1, 0, 0.5, 0.1) and would return the log of the PDF. An example call to the (logged) CDF is ddm_lcdf(1, 1, 1, -1, 0, 0.5, 0.1) and would return the log of the CDF.

Expected Output

We should expect the example call to ddm_lpdf(1, 1, 1, -1, 0, 0.5, 0.1) to return 0.02250968. We should expect the example call to ddm_lcdf(1, 1, 1, -1, 0, 0.5, 0.1) to return 0.7264627.

Current Version:

v4.1.0

syclik commented 1 year ago

Sorry for the late response. I see the PR associated with this and I'll make comments.

First question: is this the right name to call it?

I'll review the code in earnest now.

Second question: can you write down the distribution here in math or link to papers?