Skip to content

Adding 7-Parameter Drift Diffusion Model (DDM) PDF with partial derivatives to Stan Math #2682

@Franzi2114

Description

@Franzi2114

Description

The Drift Diffusion Model (DDM) introduced by Ratcliff provides a framework for analyzing data of fast binary decisions jointly modelling accuracy and response times. There are several parameterizations of the DDM. Currently Stan Math contains the PDF of the 4-parameter variant (i.e., the parameters for threshold separation, non-decision time, relative starting point, and drift rate) in the function wiener_lpdf(). Furthermore, @kendalfoster is working on a 5-parameter variant of the DDM (i.e., including the parameter for inter-trial variability in the drift rate) (see issue #2584)

I am working on a pull request to add a 7-parameter variant with partial derivatives of the DDM (i.e., additionaly including the parameters for inter-trial variabilities in relative starting point and non-decision time). For this goal, I first want to implement the lpdf and lcdf of the 4-parameter model wiener4_lpdf and wiener4_lcdf containing partial derivatives. In the next step, I want to use these functions to expand the model to a 7-parameter model containing partial derivatives wiener7_lpdf and wiener7_lcdf. These wiener7 functions will be built in the way that they call the wiener4 functions for the case that all three variability parameters are set to 0. Almost all computations are done on the log scale which makes computations more stable. All functions will be based on the implementation of the R-package WienR by @RaphaelHartmann. (Therefore, checks whether the correct values are computed can be done via the WienR package in R).

The 4-parameter functions will accept the following parameters: response time, threshold separation, drift rate, relative starting point, non-decision time, precision, response.

The 7-parameter functions will accept the following parameters: response time, threshold separation, drift rate, relative starting point, non-decision time, inter-trial variability drift rate, inter-trial variability relative starting point, inter-trial variability non-decision time, precision, response.

(There may occur minor changes in the parameter lists).

The idea is to implement the 7-parameter model in the way that it also can be used as a 4-, 5-, or 6-parameter model. For this, the user only has to set the corresponding variabilities to 0.

Example

4-parameter model:
An example call to the lpdf is wiener4_lpdf(1, 1, -1, .5, .1, .01, 1) and would return the log of the PDF.
An example call to the lcdf is wiener4_lcdf(1, 1, -1, .5, .1, .01, 1) and would return the log of the CDF.

7-parameter model
An example call to the lpdf is wiener7_lpdf(1, 1, -1, .5, .1, .5, .6, .7, .01, 1) and would return the log of the PDF.
An example call to the lcdf is wiener7_lcdf(1, 1, -1, .5, .1, .5, .6, .7, .01, 1) and would return the log of the CDF.

Expected Output

We should expect the example call to wiener4_lpdf(1, 1, -1, .5, .1, .01, 1) to return -4.24659 .
We should expect the example call to wiener4_lcdf(1, 1, -1, .5, .1, .01, 1) to return -1.323102.

We should expect the example call to wiener7_lpdf(1, 1, -1, .5, .1, .5, .6, .7, .01, 1) to return -1.90939.
We should expect the example call to wiener7_lcdf(1, 1, -1, .5, .1, .5, .6, .7, .01, 1) to return -1.289187.

Edit

In a first step, I want to implement wiener_full_lpdf. This function will be able to compute a 4-, 5-, 6-, and 7-parameter model. So: wiener4_lpdf and wiener7_lpdf will be parts of wiener_full_lpdf. The cdf function will be postponed.

Second Edit

The 7-parameter model wiener_full_lpdf is now implemented. We do not implement the 4-parameter model seperately and we also do not implement the CDF functions. The 7-parameter PDF functions are now in the testing phase and will soon be availabe.

Open Questions

I already started the implementation. There are still some open questions:

  • Set the precision to a fixed value?
  • Or let the user set a precision and set a default for the case the user does not give a precision?
  • Then: How to implement a default value? Or if-statement whether the user set 0 and then internally set the precision?
  • At the moment I am working on a solution to use hcubature or a similar routine.
  • Edit To incorporate the other two inter-trial variabilities I have to integrate over two variables. Therefore, I need to compute two bounded integrals to obtain the 7-parameter PDF. Is there a way to compute these integrals in Stan?
  • Is there a way to translate the GPLv2+ hcubature into Stan-style and use it in BSD3 Stan-math?
  • Can I somehow combine Julia with Stan?
  • As the computation of the derivatives is quite long, I compute the derivatives outside the lpdf function in an extra function. Shall I let the functions for the derivatives in the same file as the lpdf or save them in additional files? Then: Would stan/math/prim/prob be the correct spot to save the derivatives?
  • When do I need the bool<propto>?
  • How to deal best with responses?
  • In the DDM there are two response options: Upper bound = 1, lower bound = 0. The current wiener_lpdf only computes the lpdf for upper bound responses. For the lower bound responses the user has to change the input data. But it is also possible to give the response as a parameter to the function and then choose the upper/lower bound model internally. Do you have suggestions/pros/cons?
  • Edit Now, the functions for wiener_full_lpdf are almost ready for the pull request. Which tests and steps do I have to do before I send the pull request? Can anybody give me a list or a link where I find everything?

Current Version:

v4.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    distributionsIssues that deal with distribution functions: pdf, pmf, cdffeature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions