The clean_attention
function identifies and removes responses
from participants who failed attention checks in a survey dataset. It operates
by comparing participant responses to a set of correct answers. It can be
configured to treat missing responses as incorrect. The function calculates
the total number of correct responses per participant and removes participants
who do not reach a specified minimum number of correct answers.
Usage
clean_attention(
data,
questions,
correct_answers,
min_correct = 1,
set_missing_to_zero = FALSE
)
Arguments
- data
A dataframe where attention check failures need to be identified and removed.
- questions
A character vector of column names in the dataframe that represent the questions used for attention checks.
- correct_answers
A numeric vector of the correct answers to the attention check questions. Must be the same length as the
questions
vector.- min_correct
The minimum number of correct answers a participant must have to be retained in the dataframe (default is 1).
- set_missing_to_zero
A logical value indicating whether missing responses should be treated as incorrect (default is FALSE).
Value
A dataframe where responses from participants who failed the attention checks have been removed.
Examples
if (FALSE) {
# Generate some data
df <- data.frame(
q1 = c(1, 2, 3, 2, 2, 1, 3, 2, 1, 2),
q2 = c(2, 2, 3, 1, 2, 3, 2, 3, 1, 2),
q3 = c(3, 2, 1, 2, 2, 3, 1, 3, 2, 1)
)
# Specify the correct answers
correct_answers <- c(2, 3, 1)
# Clean the data
clean_data <- clean_attention(df, questions = c("q1", "q2", "q3"),
correct_answers = correct_answers, min_correct = 2, set_missing_to_zero = TRUE)
}