How to install and use HDDM

Feburary 14, 2021 update: Please note that this blog post was outdated because of the updates of Anaconda/miniconda.

August 2020 update: I’ve created a HDDM docker image, which can be easily installed and used after installing docker.

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 are a few tips on how to install and use HDDM, in case that you plan to replicate my analyses using the code and data I share here on Github.

The targeted reader of this post are Windows users. (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 the 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

# To deactivate an active environment, use:
conda deactivate

Step 2: install HDDM

Now you have a python 3.5 environment, you can then install the HDDM package. Of course, you need to activate the py35 environment first. Then:

2.1. Install HDDM by 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. A final step is to use an appropriate editor for editing and running the scripts. I used both jupyter lab (an updated version of jupyter notebook, but you can use 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, if you like, 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 stored the scripts and data, and type jupyter lab to open run jupyter lab. Note the (weird) way to change directory in windows system.


cd /d c:\goodme\2_pilot_study\Results\4_hddm\  # in windows you have to add /d to change the directory

# run in jupyter lab or jupyter note book, 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 means that I may assume you know what I know 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.

元自我研究小组
元自我研究小组

If (hu)man is the measure of all things, what is the measure of human? matter.