Press "Enter" to skip to content

Tag: Rstats

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., to 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 have a fully reproducible example, we need a way to capture the different versions of the R packages we were using, at that particular time.

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 with 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 targets 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).

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

In R statistical environment, you are able to carry out a variety of statistical and graphical techniques. For instance, linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, and many more can be carried using both frequentist and Bayesian paradigms.

If you are new to R, you may want to start with R commander. This will provide you with a menu making the process of  learning R a bit easier at the beginning. R can be downloaded here: The Comprehensive R Archive Network.

R Resources

One of the main things that I like with R is the broad and helpful community. This also means that there are many good resources for learning the language.

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‘,  usin 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