Author Archives: Chuanpeng Hu

How to install and use HDDM

HDDM is a python package for drift diffusion model (DDM, see 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 (!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

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.

My 2018

I’ve been lived in 2019 for almost 24 hours, but so procrastinated to sum my past year up and prepare myself for a new year.  So here I just briefly list what’s significant for me in 2018.

(after spending 5 minutes to clear the screen of my laptop)

  1. Keep mental health in the increasingly stressful academia. Don’t get me wrong, I am not talking about the lab I am working in, we enjoy the relaxed and freedom in our lab. But this intellectual environment cannot stop the chronic stress of academia penetrate into your life. The stress comes when it seems that all your peers published great papers but you don’t; when the future employers seem to only care about the impact factor of the journals you published and the number of your papers but you seem to unqualified, both in terms of quality and quantity. There are many statistics showing that there are more qualified people but few positions for them, young people on the social media also showed anxiety about their future. I can hardly be an exception. Nevertheless, I am still mentally healthy (also physically healthy, not gaining weight).
  2. Survived in a foreign culture. Culture matters. I can feel that some compatriots are really suffered emotionally because we are relatively isolated. As a Chinese adult, or East Asian more broadly, it is extremely difficult to have a comfortable friendship. By comfortable, I mean you don’t need to play really hard to maintain the relationship. The difficulty lies not in the characters of people, there are very nice people around. But it lies in the way to interact with people in a different culture. This problem becomes worse for a guy not so social and talkative as me. Even in China, I only have a few friends who were accumulated in years. So here it is even more difficult for me to get new friends, still, I am able to keep fit and optimism. That’s an achievement! I should thank my girlfriend, who makes me feel home, even when she is in Amsterdam.
  3. Feel much better for new projects. I come to the current lab from a different background (Thanks to my supervisor’s open mind). So in the beginning, I felt that everything is new to me. After about one year’s learning, I finally start to “do” something, instead of just learning. I felt that the new things I’ve learned in the past year are as many as half of what I’ve learned during my Ph.D.  I also found that learning new methods, paradigms are so interesting: it seems that you have new lens through which you see new things of the world.
  4. The unfinished projects during my Ph.D … are still not finished in the last year. My experiments during my Ph.D are still not published, though the data and results have been there for more than two years. That’s one aspect that I really don’t like academia: you have to wait years to make your research public. I always wonder: does the slow process of the “publication” mean that the experiments I’ve finished are actually not so important? Otherwise, why other groups haven’t done similar experiments and publish their results? Of course, it will be worse if the other groups indeed published similar results, but this makes me really doubt the value of what I have done. If it is only for making the publication list of my CV longer, then why should I do those meaningless kinds of stuff?
  5.  I am proud that I am still promoting open science. It becomes quite clear to me that many published papers are meanless and will never advance human knowledge (actually they can be worse because they are misleading and confusing, keep consuming more time, money and efforts of young graduates). So getting more people to know about the open science may actually be more valuable than publish some craps. In 2018, I published three papers related to this, the 1st introduced Bayes factor to Chinese colleagues, the 2nd reports the how psychological students and researchers misunderstand p-value and confidence intervals, the most widely used statistical index; the 3rd commented on the importance of open science to the legal system. Also, together with other colleagues and friends in China, we finished two more Chinese papers on open science, one introduced the reporting standard of meta-analysis, the other introduced how to calculate and report confidence intervals of effect size. These two papers mean something to me because they indicate more junior colleagues are jumping in the open science movement, I won’t feel alone.

Maybe, one most important changes for me in 2018 is about the future direction of my research and where we will live in the future (with my girlfriend).

In the past year, I always ask myself: what is my research question? what is my unique method. Now, it seems clearer to me that I like Bayesian statistics and cognitive models, that’s the methods that I should polish in the future. As for the research question, I have the feeling that I want to study the non-WEIRD population, especially those in a disadvantaged situation, study their mental health, brain, and how to improve their well-being. Maybe, I should work with sociologist some day.

One important decision my girlfriend and I have made is that she will go back to China after graduate from her master program in the mid of 2019, and I will stay abroad for two or three more years and then go back too. It’s an important decision, but also a natural decision. My girlfriend is the only child of her family, she feels the imperative to go back and look after her parents. For me, going back would provide me with a good chance to study the non-WEIRD population, because many Chinese people still in poverty and they need to be known. However, I should learn more before I become independent.

Farewell, 2018.

Hello, 2019, go!

References for beginners on skin conductance response (SCR)

Skin conductance response (SCR) is a widely used psychophysiological measurement in psychology, especially emotion studies. Even it is a relatively old method used in psychology, it seems that there is no explicit standard you can use, more or less the tips are told by your colleagues instead of from an explicit guidebook.

Here I record the articles, books, and manuals that helped me to know more about SCR, which I will be used in a fear extinction study.

The workflow of the SCR is not complex, only three steps:

Recording. The most or lest important thing you need to care, depending on your lab’s experience. It is the most important thing because data quality is always the most important aspect of research. “garbage in, garbage out”. It is the lest important thing because usually you just follow the way your lab’s done before. The question in this step is: which part of the body will you stick the electrode, how can you get good signals.

Preprocessing. surprising! With a cognitive psychology background, I’ve thought that only EER & MRI data need a preprocess, but actually, SCR data need that too (actually all kinds of data need a preprocess, the only difference is how much time it cost and how complicated it is).

The preprocess of SCR data usually include a low-pass filtering or down-sampling. After that, you begin to deal with the real data.

The question at this stage is: first, the time point of the onset of SCR (Levinson and Edelberg 1985 reported that 1000 ms ~ 4 000ms after the onset of stimuli were used most frequently, from Boucsein, 2013; we use 900 ms ~ 4 000 ms).

Second, after knowing the onset, the next step is how to calculate the magnitude (Important Note: amplitude and magnitude are different things in SCR, sum non-zero amplitudes / number of non-zero responses = mean amplitude; mean magnitude = mean value computed across all stimulus presentations including those without a measurable response). which threshold used to judge one trial has SCR or not (zero-response)? There is also no standard way for this. Braithwaite et al. (2015) mentioned that historically the most common threshold is 0.05 µS, but now the common threshold is range from 0.01 to 0.04 µS. In our study, we used 0.02 µS.

After extract the SCR amplitude value, the data need to be normalized and standardized. Braithwaite et al. (2015) make a good distinction between the two: Normalization is to make data of each participant more like parametric data (therefore can subject to parametric data analysis), which is necessary; standardized is between participants, to make each participants’ data comparable to each other, which is not always necessary. There are many different ways to do the normalization and standardization, Braithwaite et al. (2015) give many typical approaches, please check the document (p10 ~ p11).

In our lab, we used magnitude, which is the normalized log transformation (log(S+1), S =  raw magnititude); for standardization, we used the range-correction ( (SCL – SCLmin) / (SCLmax – SCLmin: Dawson et al., 2001)).

Analyzing: after preprocessing, do whatever statistic you like.


Related software:

Of course, my understanding might be wrong, cause I am also a beginner in this field. So here are the references and what I learned from each:

First of all, EDA or SCR is not as simple as it appears to be. At least there are books about it. Here are two examples:

Boucsein (2012), Electrodermal Activity (2nd). Springer

Greco, et al., (2016), Advances in Electrodermal Activity Processing with Applications for Mental Health. Springer.

Second of all, check the guideline from the Society of Psychophysiology, the have a Publication recommendation for electrodermal measurements. In section 3.1, there is one paragraph about the latency of SCR, which is a good rule of thumb about how you shall decide which part of your data is SCR. This section also mentioned different index of SCR: amplitude, area under the EDR curve etc.

Then, there are some terms that you might want to know before jump into all the mess, and Boucsein (2012) have made a table to make life easier:

Braithwaite et al. from Birmingham have a very clearly explained online guide. If you only want to read one document, this one is recommended. The link is here.

Braithwaite, Watson, Jones, & Rowe, A Guide for Analysing Electrodermal Activity (EDA) & Skin Conductance Responses (SCRs) for Psychological Experiments.

For a practical and brief introduction, please see:

B. Cowley, M. Filetti, K. Lukander, J. Torniainen, A. Henelius, L. Ahonen, O. Barral, I. Kosunen, T. Valtonen, M. Huotilainen, N. Ravaja, G. Jacucci, The Psychophysiology Primer: A Guide to Methods and a Broad Review with a Focus on Human–Computer Interaction DOI: 10.1561/1100000065. 

Another often-mentioned book chapter (of which book the founder of social neuroscience John Cacioppo is the editor):

Dawson, M. E, et al. (2000). The electrodermal system. In Cacioppo, J. T, Tassinary, L. G. & Berntson, G. (ed), Handbook of Psychophysiology. Cambridge University Press, Cambridge UK, 2nd edition, 2000. 















可重复危机更新:Methodological Terrorism

关于“可重复的危机”事态的发展,有些超出纯粹学术的讨论,带有许多网络争议中常有的戾气,这种戾气随着最近Susan Fiske在APS官方在线杂志Observer上一篇文章的流出而引起了(西方)心理学家集体刷屏。不过虽然说各个参与讨论的人内心可能各种涌动,但是讨论起来,还是挺有分寸的。至少主流是那些比较折衷同时兼顾各方的人。

Fiske写了一篇题为Mob Rule or Wisdom of Crowds?文章,在这个文章中,她作为社会心理学的老前辈(Handbook of Social Psychology的编辑之一),批评了当前许多人在网络媒体(博客、facebook、twitter等)上对同行的研究进行批评与讽刺的行为,并且这种“方法恐怖主义”引起了不少人离开学术界。(点击这里下载:fiske-presidential-guest-column_aps-observer_copy-edited

“…. all because of methodological terrorism.”

此文迅速在学术界的社交媒体上传播开来。引来了非常多的评论,有非常大胆的公开信(见下图,来自英国Cardiff大学的Chris Chambers,Pre-register的推广者),也有各种各样在博客上的反驳,我列出目前几个比较有影响的博客文章。

哥大统计学家和政治学家的评论:What has happened down here is the winds have changed。主要的观点是时代变了。顺便一说,他后面一篇关于为什么可重复性在心理学领域特别成为问题的博客也值得一读:Why is the scientific replication crisis centered on psychology?。

Johns Hopkins大学的统计学家Jeff Leek的评论Statistical vitriol。这里提到了一个有趣的观点是,现在许多学术界的老前辈是在数据相对少的年代成长的,他们的统计训练很少,在现在数据多、数据开放的时代有点不适应。另一个观点是:统计学家在各个学科都不太爱重视,虽然各个学科都在用统计。

我非常喜欢的一个博客[citation needed](博主Tal Yarkoni, UT-Austin心理学系的助理教授)写了一篇非常长的博客:There is no “tone” problem in psychology。作为年轻人,他也知道大家不愿意看太长的博客,所以在开头列出了他的观点:

1. There is nothing wrong with the general tone of our discourse in psychology at the moment.

2. Even if there was something wrong with the tone of our discourse, it would be deeply counterproductive to waste our time talking about it in vague general terms.

3. Fear of having one’s scientific findings torn apart by others is not unusual or pathological; it’s actually a completely normal–and healthy–feeling for a scientist.

4. Appeals to fairness are not worth taking seriously unless the argument is pitched at the level of the entire scientific community, rather than just the sub-community one happens to belong to.

5. When other scientists do things we don’t like, it’s pointless and counterproductive to question their motives.

还有一个经常对已经发表的文章提出批评与质疑的博客Neuroskeptic,也写了一篇评论:Terrorist Fiske Jab: On “Destructo-Criticism”。配图是这样的:

当然,Fiske写完这个文章之后,知道自己可能会惹火上身,她也接受了采访,进行了一些回应:We talked to the scientist at the center of a brutal firestorm in the field of psychology.

然后Chambers写了一个针对这个采访的反驳:“Methodological terrorism” and other myths“。这个里面提到了之前写的一些非常好的博客。感受一下配图:

还有一个叫Error Statistic Philosophy的博客,也写了一篇博客对此事进行评论:A new front in the statistics wars? Peaceful negotiation in the face of so-called ‘methodological terrorism’。在这篇博客中,也有统计学出身的人留言,表示统计学在各个领域中其实不受重视,地位低下。

总之,最近关于methodological terrorism这个词,心理学家们已经开始讨论(撕)得非常厉害了。当然,在公开讨论的人中间,基本上都是拿到了tenure的人,再怎么说话也不用担心自己的饭碗问题,而年轻的博士或者博后们,好像没有什么人站出来发言。