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!

Memory and attention


In the environment, we are constantly bombarded with a great range of stimuli. Most of these stimuli are of no relevance to us and we have the ability to successfully filter out most of them. This ability to filter out certain stimuli is referred to as selective attention. Part of my research concerns how some stimuli still breaks through the filter and capture our attention. In this line of work there has been shown individual differences in the ability to successfully filter out irrelevant information. For instance, people with greater working memory capacity has shown to be less distracted by auditory distractors (i.e., one’s own name) than individuals with low working memory capacity (e.g., Conway, Cowan & Bunting, 2001. In this post I will focus on the Working Memory (WM) and its interaction with attention. The basis of this discussion will be chosen parts of a review by Awh, Vogel, and Oh (2006).

Interaction between attention and working memory

It has been suggested that attention is “a gatekeeper that determines which items will occupy the limited workspace within working memory” (Awh et al., 2006). In a paradigm called Attentional blink it in which participants are to identify and report two visual targets rapidly presented following each other. Typically in this paradigm is that processing of the second target is impaired for over 100 ms. Awh, et al. argues that the effect of attentional blink is reflecting a bottleneck in the encoding into WM which will result in the impairment of the second target. This would, in Awh and colleagues view, be a type of goal-driven encoding that reveals one aspect of attentional control. Moreover, it has been found that semantic information in the second target will enter working memory and, therefore, be processed. The integrity of stored representation within WM is further argued be determined by internal shifts in attention.

Furthermore, it has been suggested that covert shifts of spatial attention could facilitate information held in spatial working memory in the same manner that is covertly articulating has been shown to aid maintenance of information within phonological WM. This is called the attention-based rehearsal hypothesis. Moreover, holding an object from the environment will also lead to attentional capture from a subsequent presentation of that object. Both holding spatial locations in WM and spatial attention show overlapping neural substrates. The areas that Awh, et al. points out that there are overlapping areas of the frontal and parietal cortex between spatial WM and spatial attention. Moreover, the lateral intraparietal sulcus (LIP) has been found to be activated by both selective attention and working memory. In monkeys LIP has been found to be activated when remembering locations (e.g., Bisley & Goldberg, 2003).

However, in the Visual Search paradigm, data has been collected that does not follow the attention based hypothesis. In this paradigm, the participants are to hold an object in WM matching a distractor in a search array in half of the trials. If objects in WM would capture attention in an obligatory manner search rates should be slower when the distractor and the object held WM matched. This effect has not been found in many studies. Awh et al., (2006) suggests that objects in memory can indeed capture attention but this effect can be suppressed by other interactions within the WM.


That there is an interaction between working memory and attention seems to be quite clear. However, one might wonder in which direction this interaction is taking place. There are other researchers that have focused on working memory capacity (WMC) and attention. It has been found that people with high WMC are less prone to get distracted by the presentation of distracting sounds (Cowan et al., 2001; Sörqvist, 2010). Moreover, it has been found that low people with WMC show greater proactive interference, worse performance in antisaccade tasks, the Stroop task, and more prone to be distracted by the dichotic listening task (see Engle, 2002 for a review).

Furthermore, ADHD, which is an attentional disorder, is related to less activity in the dorsolateral prefrontal cortex (DLPFC), intraparietal sulcus (IPS) and supplementary motor area (SMA) (Konrad & Eickhoff, 2010). Individuals with ADHD also often have low WMC which has led some researchers to suggest that it is the WMC that is one of the problems related to inattention. Furthermore, in a study examining the neural correlates of the executive functions the intraparietal sulcus has been also suggested to be related to amodal selective attention to relevant stimuli and suppression of irrelevant external stimuli (Collette et al., 2005). That is, the intraparietal sulcus seems to correlate with the executive function inhibition as well. Indeed, the executive functions have been found highly correlated to WMC (McCabe et al., 2010). Could the intraparietal sulcus be one of the keys here? To be able to sustain attention you most often need to be able to suppress irrelevant information such as people talking, etc.

In conclusion, there is an obvious interaction between attention and working memory but how this interaction is taking place is somewhat unclear. Without the ability to sustain attention it seems hard to maintain items in working memory but there also seems to be a connection between working memory and the ability to selectively attend. It is maybe here some other control functions such as the executive functions come to play? It seems that there are a plethora of psychological constructs that might share the same underlying brain structures. Personally, I would prefer that researchers united on a few constructs. Finally, more research in this area of interactions between attention and working memory is needed.


Awh, E., Vogel, E. K., & Oh, S.-H. (2006). Interactions between attention and working memory. Neuroscience, 139(1), 201–8. doi:10.1016/j.neuroscience.2005.08.023

Collette, F., Van der Linden, M., Laureys, S., Delfiore, G., Degueldre, C., Luxen, A., & Salmon, E. (2005). Exploring the unity and diversity of the neural substrates of executive functioning. Human brain mapping, 25(4), 409–23. doi:10.1002/hbm.20118

Conway, R., Cowan, N., & Bunting, M. F. (2001). The cocktail party phenomenon revisited: the importance of working memory capacity. Psychonomic bulletin & review, 8(2), 331–5. Retrieved from

McCabe, D. P., Roediger, H. L., McDaniel, M. a, Balota, D. a, & Hambrick, D. Z. (2010). The relationship between working memory capacity and executive functioning: evidence for a common executive attention construct. Neuropsychology, 24(2), 222–43. doi:10.1037/a0017619

Konrad, K., & Eickhoff, S. B. (2010). Is the ADHD brain wired differently? A review on structural and functional connectivity in attention deficit hyperactivity disorder. Human brain mapping, 31(6), 904-16.

Sörqvist, P. (2010). High working memory capacity attenuates the deviation effect but not the changing-state effect: further support for the duplex-mechanism account of auditory distraction. Memory & cognition, 38(5), 651–8. doi:10.3758/MC.38.5.651

Python library of the week: Bokeh

Python has a large community. Thus, there are a huge amount of libraries that are awesome.

In this article, I will acquaint you with the universe of potential outcomes in information visualization utilizing Bokeh and why I think this is an absolute necessity learn/use library for each data researcher out there.

Bokeh is a Python library for intuitive visualization that objectives web browsers for representation. This is what makes Bokeh different from many other representation libraries.

As should be obvious, Bokeh has multiple language (Python, R, lua and Julia). These bindings create a JSON document, which fills in as an info for BokehJS (a Javascript library), which introduces information to  web browsers.

Bokeh can create rich and intuitive representation like D3.js with superior intuitiveness over extensive or streaming datasets. Bokeh can help any individual who might want to rapidly and effectively make intelligent plots, dashboards, and information applications.

Hey and Welcome!

Hey guys!

Welcome to my blog. I am going to try to update this blog weekly with interesting programming related stuff. It may be a short tutorial on how to use the excellent Python module Pandas for handling data and doing some basic analysis. It also may be some more Python general such as how to randomize a python list or just a good list of Python links. Once in a while there may be some R related posts also. I really hope you enjoy the blog. Take care.