Every Psychologist Should Learn Programming

This post aims to show why you, as a psychology student or researcher (or any other kind of researcher or student) should learn to program. The post is structured as follows. First, I start by discussing why you should learn to program and then give some examples of when programming skills are helpful. I continue to suggest two programming languages that all Psychology students and researchers should learn.

Read more

Installing Rodeo IDE on Linux

Rodeo - RStudio for Python - a good IDE for doing Data Science

I recently wrote a post on the RStudio like Python IDE Rodeo (RStudio-like Python IDEs – Rodeo and Spyder). In that post, I installed and tested Rodeo 0.44. However, Rodeo 1.0 was released in October. Rodeo 1.0 cannot be installed using Pip. Therefore, I wrote a bash script for downloading and unzipping Rodeo. Note, the … Read more

Some good Python Blogs and Resources

Python for Data Analysis

In this post you will find some really good Python Blogs and Resources. Most of these really helped me when moving from proprietary software to free and Open Source software (e.g., PsychoPy written in Python).  The links are divided into two categories: general and research. In the ‘general’ category you will find good Python resources that might be more general and introducing. That is, more helpful for general problems and you might want to start here. In the ‘research’ category there are links to good Python resources that are more specific to use in research (e.g., PsychoPy and data analysis). The links in the ‘research’ category mainly contains links to Python blogs.

Read more

Python apps and libraries for creating experiments

In this post, I will describe the existing free Python applications and libraries for creating experiments.  So far, I have only used PsychoPy, but I plan to test most of them. At least the ones that seem to be still maintained. All applications and libraries are open-source, which makes it possible to download the source code and add your own stuff to it.

Read more

Free & Useful Software – PsychoPy

PsychoPy

This post will describe why I prefer using PsychoPy before other software. When I started getting involved in research (i.e., when doing my Bachelor’s and Masters’s theses), I used the software that was accessible to me. That is, some of the most commonly used software in the department I was studying at. After starting my Ph.D. studies, I got increasingly annoyed with one of the software we used to build experimental tasks in (i.e., E-prime).

First, I was unfamiliar with the scripting language (called ‘e-basic’) that was needed, for instance, to solve pseudo-randomization and send signals to a specially built device I was going to use in my experiments. Second, I prefer to use Linux systems, and e-prime is limited to Windows. In fact, e-prime seemed to work best with Windows Vista or earlier, but our lab computers were, and are, running Windows 7 (which might have changed back then). Some time into my Ph.D. studies, I found PsychoPy, which is written in Python, a programming language that I did know. It seemed like a good alternative to e-prime, and other similar software, to create experiments in.

Read more

Collecting data with Scrapy

This rather long (counting the Python code) tutorial assumes that you are interested in scraping data off the web using Scrapy. It might also be limited to Linux.

Installing scrapy

Here is how to install a Python package using pip:

pip install scrapyCode language: Bash (bash)

Note, if you need to you can also use pip to install a specific version of Scrapy as well as upgrade pip, if you have an old version. Now, to create a new Scrapy project, open up a terminal and create a directory where you will store your Scrapy projects change do that directory and run this (change ‘psysci’ to whatever your project will be named):

scrapy startproject psysciCode language: Bash (bash)

Item

We start with the Item class and create an object to store our scraped data in. In my example I scrape the article title, type of article, the article’s abstract, when the article was received and when it got accepted for publication, which year it was publicized (and month) and the articles keywords.

Read more

Reverse Scoring in Python with Pandas

reverse scores

In this post, we will learn how to reverse scores in Python. Reversing questionnaire scores is easy; this post is concise.

Why you Need to Reverse Code

We sometimes want to reverse the scoring when working with questionnaires that use a Likert scale (e.g., strongly disagree, disagree, neutral, agree, strongly agree).  For instance, in a questionnaire, subjective experiences of cognition, some of the questions can be positively worded (e.g., “I find it easy to read while talking on the telephone at the same time”). However, we often have negatively worded questions (e.g., “When there is music in the room, I find it hard to concentrate on reading”).

Data to reverse in Python
What is Reverse Scoring?

In the case of positively worded questions, we can score them like this; strongly disagree with a score of 1, disagree = 2, neutral = 3, agree = 4, and strongly disagree = 5. However, the same scoring can’t be applied to the negatively worded questions. We now need to reverse the score of these questions. In the Python example below, score 5 becomes 1, 4 becomes 2, 2 becomes 4, and 1 becomes 5. Three, on the other hand, (neutral) stays the same.

What does it Mean to Reverse Score?

To reverse a questionnaire’s scores means taking negatively worded questions and changing their coding, e.g., as one is recoded to 5.

Prerequisites

We can use the excellent Python package Pandas to reverse scores with Python. Here we will use Pandas DataFrame to read the data and reverse code the negatively worded items. To learn more about Pandas, check out my dataframe tutorial. If you need to install Pandas, you can use Pip: pip install pandas. Using pip is an excellent method to install Python packages, but sometimes, you must upgrade pip to the latest version. Finally, before going on to the reverse scoring example, it is worth mentioning that you can use pip to install a specific version of a Python package as well.

Read more

How to install PyschoPy on Linux Mint Debian Edition

How to Install PsychoPy on Linux Mint

Installing PsychoPy on Linux Mint was not straight forward.  This is a short guide on how to install PsychoPy on Linux Mint Debian edition. After some searching around on forums and such I found a solution and put it together in one place. PsychoPy is an application written in Python for creating experiments (e.g., for psychology or neuroscience). See my post PsychoPy – Free and Open Source Experiment builder written in Python for my thoughts on the software..

Read more

Python script for trial randomization

In this post you will find a Python script for randomizing conditions with constraints (i.e., never 2 consecutive trials of X). This script will in a later post be implemented in a cross-modal oddball task created in Psychopy.

I recently started to use Psychopy to build experiments. To build my experiments (mainly oddball tasks) I have, up until I found psychopy, used e-prime. In an oddball task one does not usually present several oddball (typically called “novel” or “deviant”) stimuli in succession. Without getting into detail; I was not able to solve this problem with e-primes scripting language “e-basic” so I made a python script instead. With this script I pre-generated .txt-files that I loaded into e-prime and got my constraints fulfilled.

Read more