Installing software
Before we start the course, we have to install three things:
- R: A free program for statistical programming
- RStudio: An integrated development environment (IDE) which makes it easier to work with R.
- Several packages: Separate pieces of ‘add-on’ software for R with functions to do specific analyses. Packages also include documentation describing how to use their functions and sample data.
Installing R
The latest version of R is available here.
- Click the appropriate link for your operating system and follow the instructions for installing the latest stable release.
- Depending on which OS you select, you may be given an option to install different components (e.g., base, contrib, Rtools). For this course, you will only need the base package.
Installing RStudio
Download the Free Desktop version of RStudio from the download page of the RStudio website.
Installing packages
To participate in this course, you will need a few essential R packages. Here’s an overview of the packages and why we need them:
Package | Description |
---|---|
lavaan | A sophisticated and user-friendly package for structural equation modeling |
dplyr | A powerful suite of data-processing tools |
ggplot2 | A flexible and user-friendly package for making graphs |
tidySEM | Plotting and tabulating the output of SEM-models |
semTools | Comparing models, establishing measurement invariance across groups |
psych | Descriptive statistics and EFA |
rockchalk | Probing interactions |
foreign | Loading data from SPSS ‘.sav’ files |
readxl | Loading data from Excel ‘.xslx’ files |
To install these packages, we use the install.packages()
function in R.
- Open RStudio
- Inside RStudio, find the window named Console on left side of the screen.
- Copy the following code into the console and hit
Enter
/Return
to run the command.
install.packages(c("lavaan",
"dplyr",
"ggplot2",
"tidySEM",
"semTools",
"psych",
"rockchalk",
"foreign",
"readxl"),
dependencies = TRUE)
Compiling packages from source
On Windows and Mac, R packages are distributed in two ways:
- Pre-compiled binary executables
- Binary packages can be run directly (equivalent to .exe files on Windows).
- You don’t need any special tools to install binary packages.
- Archives of source code
- Packages installed via source code must be compiled locally.
- You will need an appropriate toolchain to build and install the package.
- New versions of a package are usually distributed via source code before they get a binary release. So this option will get you the latest versions of the packages.
When you run the above command, you may see a message asking if you would like to compile certain packages from source. If so, it’s usually best to accept this option. You may also get a message asking if you want to install Rtools. A typical Windows setup is missing the toolchain needed to compile R packages from source, so the R folks have packaged the necessary tools in a standalone software bundle called Rtools.
You can find the appropriate Rtools installer through this CRAN page.
- Follow the links for your R version and operating system.