14.5 Internal consistency in R

In the following subsections, we will use the data included in the data set burnout.sav to estimate different measures of internal consistency.

14.5.1 Data wrangling

  • Starting the session in R: Start every session in R by removing all objects from the global environment using the function rm(). Likewise, set in advance the randomization seed for the current session using the function set.seed() and avoid using the scientific notation.

rm(list = ls())
set.seed(1234)
options(scipen = 999)
  • Setting the working directory: Place the data set burnout.sav in the same folder where you will set the working directory. Then, set the working directory accordingly. For example, the instructor's working directory can be found in a folder named Chapter14 that is located inside of the folder LDSwR and the folder R; all of them placed in the home folder Users.

setwd('/Users/R/LDSwR/Chapter14')
  • Loading packages: Load the packages that will be required to execute the R code for this session.

library(rio)
library(dplyr)
library(psych)
  • Reading the data set: To read the data from the SPSS file stored in the working directory, use the function import() from the package rio but do not forget to add the path with the additional folder (datasets) followed by the name of the data set with its corresponding file extension (e.g., .sav, .csv, .dat).

burnout.dat <- import('./datasets/burnout.sav')
  • Subsetting: To generate the correlation or structure matrix (P), we only need the items of the Job Burnout Scale. However, this time we will use only the 10 items that were retained after computing the Exploratory Factor Analysis conducted in Chapter 13. Thus, we are going to subset the data set to select the items 1 to 12 using the function select() from the package dplyr and then drop the problematic items i4 and i5. The resulting 10 covariates will be stored in a new R object named burnout.

burnout <- burnout.dat %>% 
  select(i1:i12) %>%
  select(-c(i4, i5))

headTail(burnout)
##      i1  i2  i3  i6  i7  i8  i9 i10 i11 i12
## 1     4   3   4   4   3   4   4   4   4   4
## 2     2   2   4   2   3   2   3   3   4   3
## 3     2   5   5   2   2   5   2   3   3   1
## 4     3   3   2   3   3   2   3   4   3   3
## ... ... ... ... ... ... ... ... ... ... ...
## 507   2   2   2   2   2   4   3   2   3   4
## 508   1   3   5   1   3   4   3   4   1   2
## 509   2   4   2   2   4   4   5   4   3   4
## 510   4   4   4   2   4   2   5   4   5   2
dim(burnout)
## [1] 510  10
names(burnout)
##  [1] "i1"  "i2"  "i3"  "i6"  "i7"  "i8"  "i9"  "i10" "i11" "i12"
  • Reverse scoring: We need to reverse the scoring of the two items that were negatively worded (i3 and i8). First, we will create a new vector (new) after selecting all the rows and only the columns of the items named i3 and i8. The vector named new is the result of subtracting a value of 6 to the scores of two items that range from 1 to 5. Consequently, a score of 1 will be transformed into a score of 5 (i.e., 6 - 1 = 5) and a score of 5 will be transformed into a score of 1 (i.e., 6 - 5 = 1). After reverse scoring the two items included in the vector new, we will substitute the original items i3 and i8 included in our data set with the new ones stored in the R object new. As usual, you can inspect the result using the function head().

new <- 6 - burnout[ , c('i3', 'i8')]
burnout[ , c('i3', 'i8')] <- new
head(burnout)
##   i1 i2 i3 i6 i7 i8 i9 i10 i11 i12
## 1  4  3  2  4  3  2  4   4   4   4
## 2  2  2  2  2  3  4  3   3   4   3
## 3  2  5  1  2  2  1  2   3   3   1
## 4  3  3  4  3  3  4  3   4   3   3
## 5  2  2  2  1  3  2  3   2   4   2
## 6  3  3  2  3  3  3  3   3   4   2