Descriptive Statistics in Python using Pandas

descriptive statistics in python

Descriptive statistics in Python are easy to calculate with Pandas. Whether you want a quick overview of your data or need summary statistics before fitting a statistical model, Pandas includes built-in functions for the most common descriptive measures. In this tutorial, you’ll learn how to calculate descriptive statistics for a Pandas DataFrame and interpret the … Read more

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

R Resources for Psychologists

R Resources for Psychology Researchers

Good resources for learning R as a Psychologist are hard to find. By that, I mean that there are so many great sites and blogs to learn R. Thus, it may be hard to find learning resources that target Psychology researchers.

Outline

The structure of this post is as follows. First, we start by getting a quick answer to the question “what is R?”. After this, we will briefly discuss good books you can use to learn R. In the next section, we will go into two other types of R resources: namely, tutorials and how-tos. This section will start by giving you some general resources and then list some R tutorials (many from this blog), and then, finally, you will get some Psychology specific R resources to learn from.

What is R?

If you are new to R, you might wonder what R is. R is a free and open-source programming language and environment. Data analysis in R is carried out by writing scripts and functions. Finally, R is a complete, interactive, and object-oriented language.

R Books for Psychologists

Recently I wrote about four good R books targeted at Psychology students and researchers (i.e., R books for Psychologists). There are, however, of course, other good resources for Psychological researchers to learn R programming.

Therefore, this post will list some of the best blogs and sites to learn R.  The post will be divided into two categories; general and Psychology focused R sites and blogs. For those who are not familiar with R, I will start with a brief introduction on what R is (if you know R already; click here to skip to the links).

Read more

R from Python – an rpy2 tutorial

rpy2 tutorial

This tutorial covers the integration between R and Python using the rpy2 package. Discover how to bridge the gap between these two languages, enabling you to make use of both languages’ strengths for enhanced data analysis and visualization. This rpy2 tutorial guides you through its installation, configuration, and practical usage.

Outline

In this tutorial, we will learn how to use rpy2 to install r packages and run r functions to conduct data analysis and visualization. We will learn how to use the r-packages ‘afex‘ and ‘emmeans‘,  using Python and rpy2.  Finally, we will also learn how to display R plots in Jupyter notebooks using rpy2, using two different methods.

Obviously, rpy2 requires that we have both R (version +3.2.x) and Python (versions 2.7 and 3.X) installed. Pre-compiled binaries are available for Linux and Windows (although they are unsupported and unofficial).

Read more

Reverse Scoring using R Statistical Environment

reverse scoring in R

In this tutorial, you will learn how to do reverse scoring in R. Specifically, we will use 1) base R to reverse selected variables (e.g., questionnaire items), and 2) we will use the Psych package.

Reverse scoring

Many instruments (e.g., questionnaires) contain items phrased so that a strong agreement indicates something negative (e.g., “When there is music in the room, I find it hard to concentrate on reading”). These items need to be reversed so that the data will be correct later for statistical analysis.

Reverse Scoring in R

For more information on reverse scoring, please see my earlier post: Reverse scoring in Python. Since I was more familiar with Python than R and had no clue how to do this in SPSS, I wrote a Python script. The Python script used a function that used Pandas DataFrame, and it reversed the scores nicely and quickly.

Questionnaire data to be reversed

Read more