ProgrammingResearchTechnology

Top programming languages for psychology researchers

These days it’s not uncommon for psychology researchers to work on projects that involve some degree of technical know-how, whether it’s for building experiments or performing data analysis. With such technical experience becoming increasingly necessary in psychology, many researchers are now considering programming as a very relevant skill to learn.

Unfortunately, it can be difficult knowing where to start when learning to program. I’ve spoken to many psychology researchers who are interested in learning but don’t know where to begin or are unsure which programming language is best suited for their needs.

In this article I’ll go over which programming languages are best suited for psychology researchers and how each language can be adapted to help you achieve specific research goals. If this still feels like too much to process I’d suggest trying not to overthink it as any of these languages will be sufficient for getting you started.

What this article is not

This won’t be a technical article, instead I simply want to make sure that you have a solid understanding of which programming languages are best suited for psychology researchers. 

Hopefully this will rid you of any doubts about choosing which language to learn and will give you peace of mind in knowing you’ve made an informed choice.

code

Which programming language is best to learn?

There is no single answer to this question. Generally speaking, any language should teach you the fundamentals of how programming works. These fundamentals will be applicable to most other languages you decide to learn thereafter. Having said that, different languages do specialise in different areas so if you have a particular interest or focus then this post will hopefully narrow down the scope of which language is best for you.

The benefits of learning to program

Programming can be extremely desirable to future employers and can boost your CV. Programming also teaches new and interesting ways to solve problems through logical thinking. Knowing any of the languages I’ll discuss here will also give you a head start in applying your skills outside of the research environment, which is handy if you ever decide to switch career.

Top five programming languages for psychology researchers

Before jumping into my recommendations, I’d like to quickly comment on the topic of how to actually start learning to code.  Some people like to dive right in at the deep end and just start coding. This might work for a few individuals, but I’ve found this often puts people off coding because they get stuck too quickly and become frustrated. My advice would be to take things slow, start right from the beginning and learn the core concepts (e.g. data types, variables etc.) before taking on your first project. Any decent programming tutorial will do, but the point is to learn how to walk before running straight into a brick wall of code that doesn’t make sense!

With that out of the way, let’s take a look at my first recommendation.

JavaScript (with HTML and CSS)

html5

JavaScript is my first, and possibly top pick for a programming language that has direct benefit for psychology researchers. JavaScript traditionally works together with HTML and CSS to create interactive websites. JavaScript controls how websites behave based on user events (e.g. a mouse click to play a video). HTML handles content such as text or images while CSS allows you to apply styling (e.g. colours, fonts etc.).

This might seem like a lot to learn but don’t worry. HTML and CSS have a very basic syntax that can be learnt in a day or two. JavaScript will take more time to learn if you’ve never programmed before, but take things step-by-step and you’ll see progress in no time.

JavaScript can be very handy for psychology researchers because it gives you the ability to build online and offline experiments. JavaScript provides total control over the functionality of your experiment, and you can tweak how it all looks using HTML and CSS.

If you decide to learn JavaScript for making online experiments, you’ll also need to learn a bit about databases for storing your results on the web. SQL is considered the traditional option for data storage, but for a more modern solution I’d recommend Firebase.

Click here to start learning HTML, CSS, & JavaScript

The standard workflow of HTML, CSS, and JavaScript

HTML organises content

<p> some text </p>

CSS adds styling

p { 

color: red;

}

JavaScript adds functionality

var str1 = ‘Hello’;
var str2 = ‘ world!’;
var res = str1.concat(str2);
document.write(res);

The final output

some text

Hello world!

An alternative to JavaScript

I like JavaScript, but the learning curve can be a bit steep for beginners. For a more manageable alternative you might want to consider Inquisit. I didn’t mention Inquisit in its own main heading because it’s not a traditional programming language. Instead, it’s a scripting language based on JavaScript that’s designed to be more accessible to non-programmers. Inquisit isn’t too versatile because its focused specifically on making experiments. But the real benefit comes from the fact that Inquisit handles data storage, so you don’t have to learn database management separately.

There are other solutions similar to Inquisit which I have discussed in a previous article here.

Python

python

Python is one of the most popular programming languages in the world, and for good reason. Its simple syntax makes it a good choice for beginners. Python is also a general-purpose language with lots of versatility. This is great for psychology researchers because it covers two very important aspects of research, building experiments and analysing data.

Python is often used for making GUI desktop applications making it well suited for building psychology experiments. This process is made easier with PsychoPy which is a software package designed specifically for building experiments in Python. PsychoPy uses much the same syntax as core Python but with added features that streamline your workflow. This makes it easier to display stimuli, record user input, and store results.

Python is also great for data analysis and is a top choice for many data scientists. Most of the time you’ll see data being analysed with Python in a coding environment called Jupyter Notebooks. This is simply an interface that makes it more convenient for loading datasets and organising your code. The general workflow involves loading in data (usually a csv file) and typing commands for inspecting and analysing your data. I think this is a great option if you want to transition away from SPSS.

Click here to start learning core Python

Click here to start learning PsychoPy

Click here to start learning Jupyter Notebooks

This is an example of the basic workflow when analysing data in Jupyter Notebooks

R

R

R is primarily used for data analysis. It’s up there with python as one of the most popular choices, and people often argue over which one is better for analysing data. I won’t dwell too much on that argument here, but see below for my own brief viewpoint.

R is great for all types of analyses, whether you’re building a simple linear model, conducting complex Bayesian statistics, or running machine learning algorithms. The syntax of R takes a bit of getting used, but after a short time learning you’ll see that it’s not really that bad and can be picked up rather quickly. R particularly shines when performing more complex stats like multi-level models that can be rather cumbersome in other environments such as SPSS. One tip is to use a software package called RStudio to organise your code better.

Interestingly, there’s a bit of an R revolution occurring. An increasing number of psychology academics are transitioning their data analyses over to R as a replacement for more traditional analysis packages like SPSS. There’s good reason for this, not only is R completely free but it’s also incredibly flexible. An abundance of downloadable packages means that R can handle almost any analysis you throw at it.

I tend to agree that there are many advantages to using R, although many researchers have spent their entire careers getting used to the convenience of SPSS and may not find the transition towards a programming workflow so smooth. Only time will tell how the R revolution will change the face of data analysis for psychology research.

Click here to start learning R

RStudio is an interface that makes it easier to organise your R code

R vs. Python: Which language is best for data analysis?

Everyone has their own opinion on this. The truth is they are both great for analysing data so don’t stress about the choice. R has the advantage of being popular for psychologists, and it’s gaining momentum, so you are more likely to be able to collaborate with your colleagues on projects. On the other hand, Python’s worldwide popularity and general-purpose nature makes it a great choice for building all kinds of applications (it’s not just restricted to data analysis) and there are plenty of tutorials and resources out there to help you get started with Python.

MATLAB

Matlab

Out of all the languages I’ll discuss in this post, MATLAB will arguably be the most well-known to psychology researchers. You may have even been taught a bit of MATLAB as part of your psychology degree. The reason MATLAB has more of a history in psychology research is because it can be used for building experiments as well as analysing data. It’s even widely used in neuroscience for analysing brain images, giving it an edge in this department over other programming languages.

Building experiments in MATLAB is achieved with the help of a package called Psychtoolbox. This gives you access to a convenient collection of functions for streamlining the entire process of building an experiment. In other words, Psychtoolbox makes it easier to set everything up including displaying on screen stimuli, recording user input, and storing participant results.

MATLAB is also a popular choice for data analysis because of the way it efficiently handles your data. In MATLAB all variables are stored as multidimensional arrays making it more efficient when performing matrix computations for linear algebra. This may not be the type of analysis you’ll be conducting (although it might be), but the point is that MATLAB has a powerful set of core features and built-in algorithms that make it appealing for analysing and processing large amounts of complex data.

The downside is that MATLAB requires a license to use, so it doesn’t have the added appeal of python or R as a free product. The good news is that if you’re using MATLAB as an academic your institution may provide a license already, so you don’t have to pay anything yourself.

Click here to start learning MATLAB

The MATLAB environment looks intimidating at first, but it doesn’t take long to get used to it

C#

unity

C# is another general-purpose programming language that can be used for building many different types of applications. For psychology researchers, C# can be especially useful for building highly interactive online and offline experiments, in both 2D and 3D. In fact, C# is a big player in the indie video-game market. You could think of psychology experiments as being a lot like games themselves, with participants interacting with elements of your experiment in all kinds of different ways.

The beauty of using C# for building experiments is that you can achieve complex animations and impressive effects more easily compared to other programming languages. The ease with which you can build such experiments (or games) is achieved with a software package called Unity. This is just an environment that makes it much easier to add all the content, features, animations, and effects to your application. You build the visuals of your experiment in the Unity editor and write C# code to add functionality. When you’re done, you can even compile your experiment to work on both desktop and cross-platform mobile which saves you from having to learn how to code for both iPhone and android!

For those of you who are a bit more into the programming side, C# may be interesting to you because of the way it encourages code organisation. C# is typically written in an object-oriented style which some consider to be a more natural way of organising code into discrete entities that represent the way we think about the world.

C# and Unity are free so it’s a great choice if your experiment requires more complex animations. Just be aware that data storage will also need to be handled, so I’d encourage you to check out Firebase for a great database solution.

Click here to start learning C#

Click here to start learning Unity

The unity editor gives you lots of features to play around with

Personal picks

I said at the start of this post that there is no ‘best’ language. While this is certainly true, I thought it might still be beneficial to give you my own personal take on which languages I tend to favour. Everyone has their own personal favourites, and these are just my opinions that you may agree or disagree with.

Data analysis

I’d suggest choosing either Python or R. They are both great at analysing data, so it doesn’t really matter which one you go with.

Building experiments

My choice would be JavaScript because it teaches you web development at the same time. This gives you the added ability to edit websites using HTML and CSS.

Concluding Remarks

These were my top programming language picks for psychology researchers. I’ve given you five choices to consider along with my own personal preferences. Hopefully you can now make more of an informed choice about which language to choose. 

Good luck starting your programming journey!

Leave a Reply

Your email address will not be published. Required fields are marked *