Tag Archives: self

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 are a few tips on how to install and use HDDM, in case you are trying to replicate the analyses I shared here on Github. This post is written to help Windows users because I assume that for most Linux users, you, in most cases, can figure out how to install and use this package, at least with the help of 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 a virtue python 2.7 environment. (Note: HDDM, again, is not compatible with Python 3 after a recent update to 0.7.1)

To do that, you need first run Anaconda Prompt , which will be available after you installed Anaconda. It’be better if you run the prompt as an administrator. Then run the following code:

conda create -vv -n py27 python=2.7 jupyter  
# py27 is the name of the environment, which can be arbitrary; 
# jupyter means also install the jupyter notebook

1.3. Activate the py27 env. :

# To activate this environment, use:

conda activate py27

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

Step 2: install HDDM

Now you have a python 2.7 environment, the next step is installing the HDDM package.

To do that, you need to activate the py27 environment first. Then, follow the steps below:

2.1. Install HDDM by the following code:

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

2.2. Update kabuki, which is a 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 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 notebook, for exampe, you need to install jupyter lab in your py27 env. As follows:

conda install jupyter 

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, as below. Note the (weird) way to change directly in windows system.

# for older window version, you may need the code below:
cd /d c:\goodme\2_pilot_study\Results\4_hddm\  # add "/d" after cd

# for the latest window 10 version, you are fine without '/d'
cd c:\goodme\2_pilot_study\Results\4_hddm\

# run in jupyter notebook, for stim-based modelling
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 aware of the existence of the curse of knowledge, which means that I may assume that you have some knowledge but you don’t. So please free feel to post a comment or shout out on twitter (@hcp4715) to let me know if you have any problem when reproducing my analyses.