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 functionset.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
).
<- import('./datasets/burnout.sav') burnout.dat
- 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 itemsi4
andi5
. The resulting 10 covariates will be stored in a new R object namedburnout
.
<- burnout.dat %>%
burnout 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
andi8
). First, we will create a new vector (new
) after selecting all the rows and only the columns of the items namedi3
andi8
. The vector namednew
is the result of subtracting a value of6
to the scores of two items that range from1
to5
. Consequently, a score of1
will be transformed into a score of5
(i.e.,6 - 1 = 5
) and a score of5
will be transformed into a score of1
(i.e.,6 - 5 = 1
). After reverse scoring the two items included in the vectornew
, we will substitute the original itemsi3
andi8
included in our data set with the new ones stored in the R objectnew
. As usual, you can inspect the result using the functionhead()
.
<- 6 - burnout[ , c('i3', 'i8')]
new c('i3', 'i8')] <- new
burnout[ , 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