Probably the most common Likert scale question requires people to state their level of agreement or disagreement with a statement on a symmetric scale. For our analysis, let's simulate a data set from a survey with five of these Likert scale questions. We'll use the base R function sample(), which allows you to take a random sample from a list of elements.
# Response scale labels
scale = c("Strongly disagree", "Disagree", "Neutral", "Agree", "Strongly agree")
# Simulate data
data <- data.frame(
q1 = sample(scale, size = 1000, replace = TRUE,
prob = c(0.07, 0.11, 0.08, 0.28, 0.46)),
q2 = sample(scale, size = 1000, replace = TRUE,
prob = c(0.19, 0.12, 0.11, 0.23, 0.35)),
q3 = sample(scale, size = 1000, replace = TRUE,
prob = c(0.15, 0.25, 0.14, 0.21, 0.25)),
q4 = sample(scale, size = 1000, replace = TRUE,
prob = c(0.38, 0.18, 0.13, 0.16, 0.15)),
q5 = sample(scale, size = 1000, replace = TRUE,
prob = c(0.46, 0.26, 0.07, 0.14, 0.07))
)
The first argument to sample() is the list of elements from which to choose. In our case, we specify the following five scale responses:
- Strongly disagree
- Disagree
- Neutral
- Agree
- Strongly agree
We also specify the number of samples we want to draw (1000 participants in our imagined survey) and that we want to sample with replacement (i.e., the same response option is chosen more than once). To simulate different levels of agreements for each question, we include different sets of probabilities for selecting each response option (sum = 1).
To use functions from the likert package, our variables need to be ordered factors with levels that correspond to our five scale steps.
# Set factors
col_names <- names(data)
data[,col_names] <- lapply(data[,col_names], factor, levels = scale)