Tag Archives: python

How to install and use HDDM

HDDM is a python package for drift diffusion model (DDM, see http://ski.clps.brown.edu/hddm_docs/). I used it to decompose the reaction time and accuracy data in my recent manuscript: Good Me Bad Me: Does Valence Influence Self-Prioritization During Perceptual Decision-Making.

Here is the tips on how to install and use HDDM, in case that you are willing to replicate my analyses using the code and data I share here on Github. This post is written to help window users because I assume that for most Linux users, you, in the most cases, can figure out how to install and use this package, at least with the help from the online forum (https://groups.google.com/forum/#!forum/hddm-users).

My system information: Win 10 pro, 64 bit, 16 GB RAM

Step 1: prepare the python environment:

1.1. Download and install Anaconda 3.6 or 3.7 from https://www.anaconda.com/distribution/.

1.2. Create virtue python 3.5 environment.

To do that, you need first run Anaconda Prompt , which will be available after you installed Anaconda, as administrator, then run the following code:

conda create -vv -n py35 python=3.5 jupyter  # py35 is the name of the environment, which can be arbitrary 

1.3. Activate the py35 env. :

# To activate this environment, use:

conda activate py35

# After finished your modeling, you can deactivate the active environment, use:
conda deactivate

Step 2: install HDDM

Now you have a python 3.5 environment, the next step is installing the HDDM package. Of course, you need to activate the py35 environment before proceeding.

2.1. Install HDDM by the following code:

conda install -c pymc hddm  # (or conda install -c pymc python=3.5 hddm )
-proceed?: y

2.2. Update kabuki, which is crucial package that HDDM depends on, to 0.6.2, otherwise models can not be saved. You can check the version of kabuki to make sure you do have installed 0.6.2

pip install -U --no-deps kabuki --ignore-installed

conda list # check the version of kabuki 

Step 3: use HDDM

Now, we almost ready to go. But we still need an editor for the python scripts. I used both jupyter lab (an updated version of jupyter notebook) and spyder. The script files of the former ends with “.ipynb”, the script files of the later one end with “.py”

To use jupyter lab, for exampe, you need to install jupyter lab in your py35 env. As follows:

conda install jupyter lab

After that, changing the working directory of anaconda prompt to the folder where you store the script files and data, and type jupyter lab to open run jupyter lab. Note the (weird) way to change directly in windows system.

cd /d c:\goodme\2_pilot_study\Results\4_hddm\  # add "/d" after cd

# run in jupyter lab or jupyter notebook, for stim-based modelling

jupyter lab # or jupyter notebook if you use jupyter notebook

Similarly, to run in spyder, you need to install spyder in this py35 env. 

conda install spyder

Then, type spyder to activate spyder

spyder # you will need to change the working directory in the script.

Final note: I know that there exists the curse of knowledge, which implies that I may assume that you have some knowledge but you don’t. So please free feel to post comment or shout out on twitter (@hcp4715) to let me know if you encountered any problem when reproducing my analyses.