Step 1: Importing the Packages You Will Need

You have to call in all the packages you will want to use in your analysis using the “library()” code. I have included some code below with the packages i most commonly use and when you might need them.

Note that many functions are built in to R, like ANOVAS, t-tests and regressions, so we dont need to call special programs to be able to run them.

library(readxl) # always import this, you need it to import your data file into R
library(dplyr) # getting the means and standard deviations from your data
library(ggplot2) # plotting any part of your data 
library(emmeans) # testing whether an ANOVA interaction is significant 
library(mediation) # basic mediation models
library(lavaan) # more complex mediation models and structural equation modelling 
library(effectsize) # getting effect sizes for a variety of different statistical tests
library(lme4) # multi-level modelling 
library(psych) # makes a bunch of other classic psychology tests like cronbach's alpha and correlations easier to run and interpret
library(reghelper) # simple slopes on a regression interaction 

Step 2: Clear your environment

Remember to clear your environment if you have a lot in there. Failing to clear your files can make it harder to find errors in R code if they arise. To clear your environment, click the little broom

image.png

Step 3: Getting the data into R

How to download the data from qualtrics and get it into R

  1. Download the data from qualtrics.

    1. Download the data as an excel file
    2. Make sure to click “export values” (rather than “export labels”)
  2. Before you try to open the data in R, you need to edit it in excel.

    1. Qualtrics gives data with two headers. It looks like this

    image.png

    b. You have to delete the second row before you can import the file into R

  3. Import the data into R using the code below

# create a new file called "dta" that pulls in the excel file from your computer

dta = read_xlsx("[filepath to the xlsx file on your computer]")
  1. To get the correct filepath (on a mac), right click the file and hold down the option key. Then you will see an option that says “Copy [file] as Pathname” — click that and then you can paste the pathname into R.
  2. Note that my preference is to call the file “dta” so thats what you’ll see in my code, but you can call it whatever you want

Step 4: Creating your Variables

Factor Analysis

Cronbach’s Alpha