Press "Enter" to skip to content

Tag: Rstats

How to Read & Write SPSS Files in R Statistical Environment

In this post we are going to learn 1) how to read SPSS (.sav) files in R, and 2) how to write to SPSS (.sav) files using R.  More specifically, here we are going to work with the following two R packages haven (from the Tidyverse) and foreign to:

  • Read a .sav file into an R dataframe
  • Writing an R dataframe to a .sav file

How to Import Data: Reading SAS Files in R

In this post, we are going to learn how to read SAS (. sas7bdat) files in R. More specifically, we are going to use the packages haven, and sas7bdat. Furthermore, we will also learn how to load .sas7bdat files into R using RStudio.

If you are interested in other methods on how to import data in R:

How to Use Binder and R for Reproducible Research

In a previous post, we learned how to use Binder and Python for reproducible research. Now, we are going to learn how to create a Binder for our data analysis in R, so it can be fully reproduced by other researchers. More specifically, in this post we will learn how to use Binder for reproducible research.

Many researchers upload their code for data analysis and visualization using git (e.g., GitHub, Gitlab).

No doubt, uploading your R scripts is great. However, we also need to make sure that we share the complete computational environment so that our code can be re-run and so that others can reproduce the results. That is, to make sure that other researchers really can reproduce our code, we need a way to capture the versions of the R packages we used when publishing our research.

Every Psychologist Should Learn Programming

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

R Resources for Psychologists

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 around the internet to learn R. Thus, it may be hard to find learning resources that target Psychology researchers.

Recently I wrote about four good R books targeted for 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).

R from Python – an rpy2 tutorial

Rpy2 Tutorial: How to Run R in Python

In this post, we are going to answer the question can you run R in Python? Of course, the answer is yes!; using the Python package rpy2. This package offers a Python interface to R.

In this tutorial, we will learn how to use rpy2 to install r packages and run r functions to carry out data analysis and data visualization. More specifically, we will learn how to sue the r packages 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. There are pre-compiled binaries available for Linux and Windows (unsupported and unofficial, however).

Reverse Scoring using R Statistical Environment

This post is my first on R and it will describe a method on how to reverse scores using R.

Reverse scoring in R

Many instruments (i.e., questionnaires) contain items are 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.

For more information on reverse scoring, please see my earlier post: Reverse scoring in Python.  Since I was more  familiar with Python  compared to R, and I had no a clue on 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 nice and quickly.

Questionnaire data to be reversed