Giter Club home page Giter Club logo

mdnunez / pyhddmjags Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 9.0 642 KB

Repository for example Hierarchical Drift Diffusion Model (HDDM) code using JAGS in Python. These scripts provide useful examples for using JAGS with pyjags, the JAGS Wiener module, mixture modeling in JAGS, and Bayesian diagnostics in Python.

License: GNU General Public License v3.0

Python 51.38% Stan 1.65% Jupyter Notebook 46.97%
bayesian-inference jags decision-making hddm mcmc-methods

pyhddmjags's Introduction

pyhddmjags

(Repository version 0.7.1)

Repository for example Hierarchical Drift Diffusion Model (HDDM) code using JAGS in Python

Authors: Michael D. Nunez from the Psychological Methods group at the University of Amsterdam

Possible citation

Nunez, M. D., Fernandez, K., Srinivasan, R., & Vandekerckhove, J. (2024). A tutorial on fitting joint models of M/EEG and behavior to understand cognition. Behavior Research Methods. https://doi.org/10.3758/s13428-023-02331-x

Prerequisites

Python 3 and Scientific Python libraries

For these next install steps in Ubuntu, see jags_wiener_ubuntu.md in this repository.

MCMC Sampling Program: JAGS

Program: JAGS Wiener module

Python Repository: pyjags, can use pip:

pip install pyjags

See also yaml/pyjags.yml

Optional Stan + PyStan

The newest version of PyStan was PyStan 3, but I didn't find PyStan 3 as easy to use with custom diagnostic and plotting scripts as PyStan 2.

Here are the docs for PyStan 2

See also yaml/pystan.yml

Downloading

The repository can be cloned with git clone https://github.com/mdnunez/pyhddmjags.git

The repository can also be downloaded via the Code -> Download zip buttons above on this Github page.

Getting started

At the moment each script can be run individually to simulate from hierarchical drift-diffusion models (HDDMs) and then find and recover parameter estimates from those models. The most simple HDDM lives in nolapse_test.py. See other scripts: recovery_test.py, blocked_exp_conds.py, and regression_test.py. These scripts provide useful examples for using JAGS with pyjags, the JAGS Wiener module, mixture modeling in JAGS, and Bayesian diagnostics in Python.

The script nolapse_test_pystan.py contains pystan and Stan code to find and recover parameters from the exact same HDDM written in JAGS within nolapse_test.py. Note that this script will not work with the newest versions of pystan (pystan 3). One solution is to create a Python environment using conda:

conda create -n mcmc python=3 numpy scipy pystan==2.19
conda activate mcmc

Note that you may need or want to create a separate environment for pyjags using conda:

conda create -n jags python=3.8 numpy
conda activate jags
pip install pyjags

License

pyhddmjags is licensed under the GNU General Public License v3.0 and written by Michael D. Nunez from the Psychological Methods group at the University of Amsterdam.

Usage examples

Nunez, M. D., Gosai, A., Vandekerckhove, J., & Srinivasan, R. (2019). The latency of a visual evoked potential tracks the onset of decision making. NeuroImage. doi: 10.1016/j.neuroimage.2019.04.052 (See repository encodingN200 associated with this paper for specific pyjags examples.)

Lui, K. K., Nunez, M. D., Cassidy, J. M., Vandekerckhove, J., Cramer, S. C., & Srinivasan, R. (2021). Timing of readiness potentials reflect a decision-making process in the human brain. Computational Brain & Behavior. (See repository RPDecision associated with this paper for a specific HDDM in JAGS using MATLAB.)

Nunez, M. D., Vandekerckhove, J., & Srinivasan, R. (2017). How attention influences perceptual decision making: Single-trial EEG correlates of drift-diffusion model parameters. Journal of Mathematical Psychology, 76, 117-130. (See repository mcntoolbox associated with this paper for a specific HDDM in JAGS using MATLAB.)

Nunez, M. D., Srinivasan, R., & Vandekerckhove, J. (2015). Individual differences in attention influence perceptual decision making. Frontiers in Psychology, 8. (This paper fit HDDMs in JAGS like that in regression_test_py3.py using MATLAB and Trinity.)

pyhddmjags's People

Contributors

kiante-fernandez avatar mdnunez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyhddmjags's Issues

Question about prior distributions

Dear Dr. Nunez,
Thank you for your shares and practices. Your codes are useful for me to develop my own work.
Here, I have questions about the prior distribution of parameters that you have chosen in a stan model file named ‘stancode/nolapse_test.stan’.
Please, consider the following prior distributions in the file
//Between-participant variability in choice A start point bias
betasd ~ gamma(.3,1)
or
// Hierarchical start point bias towards choice A
betahier ~ normal(.5, .25);

How did you put the mean and std values for ddm parameters?
And what is the best strategy to determine prior distributions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.