How to Create a Psychology Experiment

Hey again,

It has been quite some busy times, lately. Anyway, in this post you will find a great tutorial video on how  to make a Psychology experiment. More exactly, it will teach you how to program a distractor inhibition task called the Flanker Task.


PsychoPy – build Psychology experiments

PsychoPy is an Python application for creating psychology experiments. It offers both a great API and a graphical user interface that require minimal programming. That is, you can create experiments without doing no programming. This is great, of course, for people with minimal to no programming experience. Below is a great intro video to PsychoPy.

Why should you program in Python?

Being an aspiring coding psychologist you may be looking for some advice and resources that are great for learning programming (i.e., Python).
This post is going to being with three reasons why you should learnt to write code:

Over the past few years, many colleagues have ranted to me about how furious they are that they did not learn coding back in high school or college, or even in University (grad school or such). They have come to realize how much more productive they could be if they had developed essential programming skills earlier.

Why Programming?


Work can be carried out so much faster by writing computer programs/scripts to automate boring tasks. For instance, cleaning your data and coding missing data in your datasets can be a very boring task to do by hand. It can of course be done with coding. Not only may your programming skills make this tasks faster (from a couple of days to few clicks away) but you may also take away human error. That is, while looking at, for instance, excel documents for a long time you may miss something that you should have changed. Your computer code, if written correctly, will not miss anything!

Your coding skills may also enable more creative solutions than your friends. I mean, those friends that DON’T know how to program. The scope of only using the tools and data that everyone else around you uses, is extended. For instance, you can code programs that scrape the web for data. You may also write your code so that your data is clean and formatted in a readable way. Finally, your data can also be integrated with old data.

The third reason is one of communicating with more experienced programmers. It will get easier. When you need to hire some to do some software for you that is out of your expertise (maybe to big for you to have time) you will know somewhat what can be created.

Why Python?

So we have dealt with some reasons on why you should code! I chose to learn Python first. So why should you learn python?


  • It is the language with the greatest potential to be used across many scientific fields. It is increasingly utilized by folks spanning from informatics to cognitive modelers. Other languages, such as R for instance, are more specific in my experience.
  • That naturally takes us to the next good thing with Python: It is a general-purpose programming language. I.e., you can do anything from creating your psychological experiments or scraping the web for data, doing the data wrangling/pre-processing, and the statistical analysis and visualizations. Finally, you will also be able to write up your results!
  • It’s free and open source. No more need for expensive and suboptimal tools! Using tools created with Python (i.e., PsychoPy) is free of charge and can be installed on any computer (i.e., running any OS). This means that your students can also use them on their private computers.
  • Many professional coders use Python. You will find a helpful and nice online community eager to give you their tips and tricks. Most universities have courses in Python (i.e., on the computer science departments).

Python tools

Interactive Development Environment

Choosing the right Python tools can be hard. First, as can be read on the blog Python Data Analysis, you should choose your interactive development environment (IDE). There are plenty to choose from but some of the best ones are Spyder, Rodeo, and PyCharm. Why are these the best? They offer so much features that one should focus one post on that rather then mention them here. If you already know coding and use MATLAB, for instance, you’d probably like both Spyder and PyCharm. However, the interface of Spyder may be more similar. Both Spyder and PyCharm offers things such as code completion but PyCharm has built in support for version control systems (e.g. Git or Mercurial). Go to the blog linked in the beginning of the paragraph if your are interested in reading more about IDEs and why you should program. There are a couple of great links on that blog.

Experiment Builders

After you have chosen your IDE you can have a look at different experiment builders written in Python; PsychoPy, OpenSesame, and Expyriment (find link from my earlier post: Expyriment – Python tool for creating Psychology experiments) are my favorite ones. PsychoPy is powerful in that sense that you can use it to build experiments with minimal coding or using its API. OpenSesame may be similar but I think that it is mainly used as a GUI for point-and-click creation of experiments. Both PsychoPy and OpenSesame offers inline scripting. Expyriment is more of an API that can be used to ease up the creation of experiment. Very nice.

Some stats packages

There are of course tools for cleaning and wrangling your data after you have collected it. For instance, Pandas offers a very R-like dataframe interface. Using Pandas visualization and descriptive statistics can be carried out. Statsmodels offers most common statistical methods (both parametric and non-parametric), sci-kit learn also offers many stats methods but focuses on machine learning, Pyvttbl lets you do repeated measures and split-plot analysis of variance. I will not go into these tools in the depth but you can read about them on other blogs.

That is all for me today!

Python Pandas tutorial

In the video below you’ll find approximately 10 minutes of introduction to Pandas:


Pandas is a great Python module that offers an dataframe interface very similar to that of you’ll find in R. Using Pandas you can carry out descriptive statistics, visualisations and data wrangling. It is a great module. Most valuable.