1  Getting Started

Before you can successfully complete the R Labs included on this page, you will need to install some software and some packages within that software. This first Lab will help you do so.

1.1 Installing New Software

As the title of this page suggests, all labs will be done using R (and RStudio). To use these programs, you’ll need to install both R and RStudio. Follow the instructions below to install them.

Step 1: Install R

R is a programming language and computing environment specialized for statistical analysis and data manipulation. It’s commonly used for performing statistical tests, creating data visualizations, and writing data analysis reports.

Installing R for Windows Computers

Go to https://cloud.r-project.org/bin/windows/base/ and click the link titled Download R-4.3.2 for Windows (note: the version number might be different, but the remainder of the link will be the same). This will download the R Installer into your Downloads folder, where you can double click on it and follow the prompts on the screen to finish installing R. You can accepts all default settings.

Installing R for Mac Computers

You will need to figure out if you have an Intel Processor or an Apple M Processor. You can do so by clicking on the Apple icon in the top-left corner of your screen and clicking on About this Mac. The window that will pop up will show you an overview of your computer, including the processor/chip used.

Once you know what processor your computer has, go to https://cloud.r-project.org/bin/macosx/, and:

  • If your computer has an Intel Processor, click on the file titled R-4.3.2-x86_64.pkg
  • If your computer has an Apple M Processor, click on the file titled R-4.3.2-arm64.pkg

Note: the version number might be different, but the remainder of the link will be the same. This will download the R Installer into your Downloads folder, where you can double click on it and follow the prompts on the screen to finish installing R. You can accepts all default settings.

Installing R for Linux Computers

If you are using a Linux-based operating system, use your system’s package manager to install R. For example, here are the instructions for installing R on Ubuntu.

Note

R cannot be installed on Chromebooks, so you’ll need to use the computers available in the classroom/computer labs.

Step 2: Install RStudio

RStudio is an integrated development environment (IDE) for reproducible scientific computing that is developed for the R programming language. An IDE is basically a nicer-looking user interface that can be customized to suit the preferences of the user. This is the actual program that we will use in class!

  • Download the latest, free version of RStudio Desktop. Be sure to get the version that is appropriate for your operating system.
  • Install RStudio Desktop by launching the installer after it downloads. You can accept all the defaults during installation.
Tip

For more detailed instructions for downloading and installing R and RStudio, you can watch this video tutorial on YouTube. To learn about (or review) R basics, you can skim this (free!) book by Navarro (2015): Learning Statistics with R. There is also the SWIRL Interactive R Tutorial that lets you learn about the basics of R while using R.

1.2 Install Necessary Packages

Throughout these labs, we will rely on a set of R packages, which add functionality to the base R language (like expansion sets of a game). These packages are typically available through CRAN or GitHub. You only need to install packages once (but you may need to update them!), so lets do that now.

We will start with a set of packages that we can download from CRAN, using the built-in install.packages function:

install.packages(c("rio", "ggplot2", "psych","correlation", 
                   "GPArotation", "lavaan", "MBESS", 
                    "devtools"))

Running the code above will install:

  1. rio: makes importing lots of different data file types easy.
  2. ggplot2: a versatile visualization package.
  3. psych: will help us cover topics such as exploratory factor analysis and reliability.
  4. correlation: includes fancy correlation coeficients
  5. GPArotation: helps with exploratory factor analysis
  6. lavaan: the main structural equation modeling package we will use to cover confirmatory factor analysis and measurement invariance.
  7. MBESS: includes additional internal consistency measures
  8. devtools: a package that helps us install packages that are available on GitHub.
Tip

If you experience issues installing the MBESS package on macOS, you likely need to install a few additional tools. Go to this page to download and install those tools: Compile Tools for macOS.

In addition to these main packages, R might also install additional packages that are needed for these 8 packages to work (so-called dependents).

Next, you will install a package, semTools from GitHub. Due to a bug in the version of this package on CRAN, we need to use the unofficial, development version of the package. You may need to uncomment (remove the #) the first line of code and execute both lines for this to work. In some cases, the download of the semTools package is too slow and results in an error because the R session times out.

# options(timeout = max(300, getOption("timeout")))
devtools::install_github("simsem/semTools/semTools")

1.3 Data Used in the R Labs

Several of the R Labs require you to download data files to use for the analyses. Links to these data files are included within each lab, accompanied by an explanation and citation.

You are now ready to continue to the second R Lab, where you will learn all about correlation coefficients.