Cognitive Architecture video

Very mind blowing and intriguing discussions on the mind. A must see!


Delta Plots on Response time data using Python

In this post we are going to learn how to do delta plots for response (reaction) time data. Response time data are often used in experimental psychology. It is the dependent variable in many experiments that aim to draw interference of cognitive processes.

Delta plots is a visualization method (Pratte, Rouder, Morey, & Feng, 2010;Speckman, Rouder, Morey, & Pratte, 2008). These visualizations (i.e., the plots) are created using the quantiles of the resposne time distribution. Research has indicated that even without a precise statistical inference test, delta plots can give the researcher key information concerning the underlying mechanisms of tasks thought to assess constructs such as, for instance, cognitive control and inhibition (Pratte, Rouder, Morey, & Feng, 2010)

import matplotlib.pyplot as plt

import numpy as np

data = {"x1":[0.794, 0.629, 0.597, 0.57, 0.524, 0.891, 0.707, 0.405, 0.808, 0.733,
    0.616, 0.922, 0.649, 0.522, 0.988, 0.489, 0.398, 0.412, 0.423, 0.73,
    0.603, 0.481, 0.952, 0.563, 0.986, 0.861, 0.633, 1.002, 0.973, 0.894,
    0.958, 0.478, 0.669, 1.305, 0.494, 0.484, 0.878, 0.794, 0.591, 0.532,
    0.685, 0.694, 0.672, 0.511, 0.776, 0.93, 0.508, 0.459, 0.816, 0.595],

    "x2":[0.503, 0.5, 0.868, 0.54, 0.818, 0.608, 0.389, 0.48, 1.153, 0.838,
    0.526, 0.81, 0.584, 0.422, 0.427, 0.39, 0.53, 0.411, 0.567, 0.806,
    0.739, 0.655, 0.54, 0.418, 0.445, 0.46, 0.537, 0.53, 0.499, 0.512,
    0.444, 0.611, 0.713, 0.653, 0.727, 0.649, 0.547, 0.463, 0.35, 0.689,
    0.444, 0.431, 0.505, 0.676, 0.495, 0.652, 0.566, 0.629, 0.493, 0.428]}

labels = list('AB')

fig = plt.figure(figsize=(10, 10), dpi=100)

ax = fig.add_subplot(111)

bp = ax.boxplot([data['x1'], data['x2']])


Here is the code that will create a Delta plot on our response time data above:

p = np.arange(10, 100, 10)

df=np.percentile(data['x1'], p) - np.percentile(data['x2'], p)
av=(np.percentile(data['x1'], p)+np.percentile(data['x2'], p))/2

fig = plt.figure(figsize=(12, 9), dpi=100)

plt.plot(av,df, 'ro')
plt.ylabel('Response Time Difference (sec)')
plt.xlabel('Men Response time (sec)')

Delta Plot

Delta Plot using Python
Delta Plot

That was pretty simple. In this tutorial you have learned how to create a delta plot that will lend you support for drawing interference of things such as inhibition or cognitive control. Drawing inference is something you will have to do for yourself! But you can have a look at the references below for more information. They will probably help.


  • Pratte, M. S., Rouder, J. N., Morey, R. D., & Feng, C. (2010). Exploring the differences in distributional properties between Stroop and Simon effects using delta plots. Attention, Perception & Psychophysics, 72(7), 2013–25.
  • Speckman, P. L., Rouder, J. N., Morey, R. D., & Pratte, M. S. (2008). Delta Plots and Coherent Distribution Ordering. The American Statistician, 62(3), 262–266.


Great list for you if you would like to learn how to create experiments using OpenSesame.  You will find tutorials in the form of text, videos, and links to blog posts and other useful resources.

OpenSesame is a presentation and reaction-time measurement software with Python scripting option Download, tutorial, information about Python scripting etc. Forum: Review: Citation and publications…

Källa: OpenSesame

Introduction Video to Statsmodels

I found this introduction to Statsmodels. For you that don’t know Statsmodels is a great Python library for conducting statistical analysis. Many common methods are covered by the package. If you want to learn more Python and Data Analysis you will most likely enjoy this Youtube video:

I surely learned more Python data analysis by watching it anyway. It makes some tasks a lot easier and makes Python more similar to R.

Inverse Efficiency Score

In this post I will briefly discuss a way to deal with speed-accuracy trade offs in response times experiments (RT). When conducting RT experiments and collecting responses such as correct and incorrect responses to visual stimuli one can at times find that under certain conditions people respond slower but more accurate. For instance if you have a condition with distractors and people are responding slower everything may seem fine. However, if you look at the accuracy data (proportion of correct responses) you may see that people responded faster. The inverse efficiency score combines speed and error. IES is suggested to be an “observable measure that gauges the average energy consumed by the system over time”. It is calculated by dividing RT by 1 – the proportion of Errors (PE), or the proportion of correct responses (PC)If two conditions have the same mean RT but differ in PE, IES of the condition that has the highest PE will increase more than the IES of the condition with the lower PEInterestingly, if there is a speed and accuracy trade-off, the IES will even out the PE differences. It is not always better to use IES. Seemingly, a lot of changes can happen when using IES. This is because it includes two variables and their sampling error. Therefore, the variability of the measure increases. Furthermore, whether the division RT by PC is a good reflection of the relative weights of speed and accuracy is unclear.

Quality Python sources

The Python community is exceptional at sharing specified resources and supporting beginners discover ways to code with the language. There are so many of sources obtainable although that it can be tough  to locate them all of them.

This post page aggregates the exceptional Python assets with descriptions of what they offer to readers.

Python for specific occupations

Python is powerful for many professions. in case you‘re in search of to use Python in a particular subject, this type of pages may be appropriate for you.

  • Python for Social Scientists here you can find a textbook, a course and slides for a university course that teaches social scientists to use Python. Pretty awesome for Psychologists (or other Social scientists, of course!)
  • Practical Business Python is a blog that covers topics such as automation of the creation of large Excel spreadsheets. Also covers how to perform analysis when your data is locked in Microsoft Office files.
  • Python for the Humanities is a basic Python textbook and course. It covers text processing. It will pretty quick become hard so after you have read the first chapter you may want to consult another introductory Python course or book at the same time.

Some iPython/Jupyter Notebooks:

I have found some useful iPython/Jupyter notebooks for learning Python. They will be categorized into fields of research.

Psychology/Cognitive Neuroscience

First we start with some specific on Psychology and neuroscience:

  • Python for Vision Research. Here you will find a three-day course for vision researchers. Focus is on building experiments with PsychoPy and psychopy_ext, learning the fMRI multi-voxel pattern analysis with PyMVPA, and understanding image processing in Python.
  • Modeling psychophysical data with non-linear functions by Ariel Rokem. General knowledge in Python is needed. You will learn a definition of modeling and get to know why models are useful, different fitting strategies, how to fit a simple model, and model selection, and more.

Statistics-related notebooks

Bayesian Data Analysis Using PyMC3

Introduction to Linear Regression – Linear regression is a commonly used statistical method in social sciences (e.g., Psychology)

Great packages/libraries to use for Data Analysis

I think that I also need to mention som great Python packages that makes data analysis way more easier in Python.

First, there is IPython. IPython is a command shell for interactive computing in multiple programming languages. It was, however, first developed for the Python programming language. For doing Scientific computing IPython is really a must (replacing the interpreter that comes with installation of Python). It offers enhanced introspection, rich media, additional shell syntax, tab completion, and rich history. You can also, as been seen above, create IPython notebooks that are, basically, html. Great! iPython is known as juPyter nowadays: Jupyter.

Here is a user manual that I got from asking a question at a blogJupyter Manual. Looks very promising.

pandas is an open source, BSD-licensed library presenting highperformance, easy-to-use statistics structures and data analysis equipment for the Python. Pandas is enabling you to carry out your data analysis workflow in Python while not having to have an extra domain specific language like R. Pandas let you do summary statistics using Python very easy. If you are familiar with R you will like the methods head, describe, and so on.

matplotlib is a 2D plotting library which enables you to create figures in publication quality. You can also create interactive environments across platforms. atplotlib can be used in python scripts, the python and iPython shell (similar to MATLAB or Mathematica), web application servers, and more. matplotlib aims to make easy things easy and hard things possible. Generation of plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc, can be carried out with just a few lines of code. For simple plotting the pyplot interface is very similar MATLAB.  Especially, when used within IPython, Spyder, or Rodeo (the last two are great Python IDEs).


There are, of course, a plethora of Python blogs. I will mention a few of them that are related to cognitive science.

There are so many more resources. Hopefully, I will update this post or make a new one later. Hope it helps you in the Python jungle, though!


Programming in Psychology

Psychology graduates often need to be, at least, computer literate on the basic level. Computers are, as in most field, used in many ways. The selection and learning of relevant packages for tasks we do are needed. However, many few psychology graduates do know computer coding. Many will have great knowledge in word-processing and statistical analysis. As you will see knowing programming will get you and advantage. You will be able to carry out tasks that not many other Psychological researchers can.

Increasingly, Psychological researchers find themselves facing exponentially larger data sets available on the internet (e.g., data mining) and elsewhere without the proper tools to handle them. A huge amount of Psychologists use spreadsheet software (e.g., Excel) for processing data. Often,  this can mean spending hours clicking around in the interface or copying and pasting. With new datasets the procedure will be repeated. Apart from being a huge waste of time, but the reproducibility the work that have previously been carried out suffer hard. It may often be completely impossible to do the exact same procedure again and the work carried out may be useless.

What kind of language should a Psychologist learn? Some programming languages, such as MATLAB and R, are commonly used by psychologists (and other cognitive scientists). These languages focus on mathematical and statistical operations. In MATLAB you are able to do psychological experiments (e.g., using Psych Toolbox), create mathematical and statistical models of cognitive functions or phenomena. Of course you can also code your statistical analysis with MATLAB. R is more focused on statistical computing, as far as I know anyway. I have seen some modelling and neural network packages for R also. However, I am yet to see a package for conducting experiments. Python is another language that has received increasing use lately. It is a general-purpose language, similar as tC and C++. However, it is a interpretative language. That is, it is a scripting language and one of the easiest languages to use. There are some packages for creating psychological experiments, such as PsychoPy,  and a bunch of libraries that can be used for scraping the web of data. Also you can conduct statistical analysis using packages such as NumPy, Pandas, and Statsmodels. In fact, the SciPy stack is very useful.

There are also JavaScript libraries to use to create experiments to run online. Running experiments online seems to be a new phenomena but give you the possibility to collect a huge amount of data in short periods of time. For instance, using Amazon Mechanical Turk seems to be popular in the US.

Programming is fun, try it!