Category Archives: Mind/Brain

About mind and brain

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.

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的人,再怎么说话也不用担心自己的饭碗问题,而年轻的博士或者博后们,好像没有什么人站出来发言。







最近看到了讨论科研中可重复性问题的视频(不仅是心理学),其中Brian Nosek提到了可重复性(reproducibility)的几层含义(23:45’到25:30′)。我觉得非常有意思,这也是我们在讨论可重复性时因为篇幅的限制而未讨论的问题[见引文],所以正好在展开说一下。




第三层:使用与原论文相同的方法和材料,看看是否能够得到原论文的结果。前段时间Replication Project: Psychology所做的工作是这一层的重复。这种重复也叫做直接重复(direct replication)。当然,直接重复面临着不少的批评,因为直接重复的过程中,可能会忽略不少的细节,有可能这些细节才是关键的,而原研究者甚至都没有意识到。所以不少研究者发现自己对其他人的研究进行直接重复时,即使失败,也会不立刻怀疑原研究,而是首先从自己的研究过程找问题。但是仅仅看论文确实是很难精确复制原实验的过程,这个问题Brian在视频中也说了;

第四层:使用与原论文不同的材料和方法,仍然得到原论文的结论。我理解的这个就是心理学中常用的概念重复(conceptual replication)。比如为了证明刻板印象启动是有效的,第一个实验启动老年的刻板印象,第二个启动婴儿的刻板印象,第三个启动嬉皮士的刻板印象,都发现了与刻板印象一致的行为表现,于是证明了刻板印象启动是有效的(婴儿和嬉皮士是我瞎编的)。这种方法在过去的研究中经常出现,Stapel也说他的结论被conceptual replicated。这个意义上的重复也是重复,但可能没有直接重复那么能力有力地证明原研究的效应确实是存在的。

这四层可重复性还只是一种观点,还可以讲方法可重复性、结果可重复性、推论可重复性等,可以参考 Goodman, S. N., Fanelli, D., & Ioannidis, J. P. A. (2016)在Science Translational Medicine上对这个问题的讨论。

此外,关于reproducibility,这个概念最早是由做计算和统计这一块的人提出的,由于他们的工作涉及到海量的运算,可能有大量的代码和脚本,一个人是否能用使用代码完全再现另一个分析,就是最原始的reproducibility的意思。这是我对Roger Peng在Coursera上关于reproducible research一课上讲到内容的理解(如果有误,那得怪我)。对这个问题感兴趣的话,可以上coursera上免费注册和学习这个课程:。



Goodman, S. N., Fanelli, D., & Ioannidis, J. P. A. (2016). What does research reproducibility mean? Science Translational Medicine, 8(341), 341ps312-341ps312. doi:10.1126/scitranslmed.aaf5027

胡传鹏, 王非, 过继成思, 宋梦迪, 隋洁, 彭凯平. (2016). 心理学研究的可重复性问题:从危机到契机. 心理科学进展, 24(9), 1504–1518 doi:10.3724/SP.J.1042.2016.01504




7月23号,psych sci的主编在自己的twitter上发推说目前psych. sci.正在测试使用statcheck工具包。




以下是我在window 10下面进行安装和测试的结果。


第二:下载 Xpdf 并且解压(下载地址:,可以选择把这个解压后的文件移动到一个存放软件程序的路径(比如我就是C:/Programfiles/xpdf)。

第三:将Xpdf添加到系统的environmental variable里,右击 this pc (此电脑) –> Properties  –> Advanced system settings –> environmental variable. 在User variable 里编辑Path,如果没有Path, 自己新建一个,把Xpdf的路径放进去。



>> # install and load statcheck

>> if(!require(statcheck)){install.packages(‘statcheck’)}



>> library(statcheck)

>> checkPDF(“C:/Users/Daniel/statcheck/Zhang2015.pdf”)


值得一提的是,并不是所有的pdf都能够读出统计值 ,至少我看了两篇APA的文档可能就无法进行检查。


为了避免麻烦,我直接把Xpdf的winow版本和Lakens提供安装英文手册使用云盘共享,链接: 密码:rpe4;下载statcheck压缩包即可。