Max Weylandt.

← Back

Straightliner: a package for detecting inattentive respondents

11 Feb 2024

I made an R package that makes it easy to calculate various measures of straightlining. The measures implemented are the ones mentioned in Kim et al. 2019.

There are other R packages for this sort of task, notably careless, which has a bunch of measures this package doesn’t include (for now at least). I wanted something that’s really convenient to use.

The main function is straightliner, which takes a dataframe and a vector of variable names (or indices as an input), and spits out a number of statistics rating how each respondent did across that set of questions. Optionally, it can add these stats to the original dataframe. It can be simple. Given this data frame …

respondent item1 item2 item3 item4
A 5 5 5 5
B 5 5 5 1
C 4 2 5 3

… a simple command …

 library(straightliner)
df <- straightliner(df, varnames = c("item1", "item3" ,"item4"), keep_original = TRUE)

yields this:

respondent item1 item2 item3 item4 mrp mir qsd spv nondiff
A 5 5 5 5 1.00 1.00 0.00 0.00 TRUE
B 5 5 5 1 0.00 0.67 2.31 0.44 FALSE
C 4 2 5 3 0.29 0.33 1.00 0.67 FALSE


I feel like most of the time, these functions will be useful for assessing which respondents to flag for inattentiveness in the process of analyzing the data. But once in a while – maybe when piloting two different sets of questions aimed at measuring the same thing – you might want to know about the aggregate amount of straightlining across all respondents for those sets of questions. For this, there is straightlining_qset():

 batteries <- list("first two" = c("item1", "item2"),
                   "last two" = c(4,5))

straightlining_qset(df, batteries, measures = c("mrp", "spv")) %>%
  knitr::kable(format = "pipe", digits = 3)
mrp spv spv_max
first two 0.667 0.167 0.5
last two 0.431 0.333 0.5

I hope you find it useful!


← Back ↑ Top