R/pattern.as.R

Defines functions pattern.as

Documented in pattern.as

#' Pattern : Responses in ascending order
#'
#' @param data The data set with the scored responses in the same order as it is administered
#' @param cols The columns belonging to the psychometric scale/scales under scrutiny
#'
#' @returns
#' The participants (rows) following the pattern, and
#' the list of said participants along with their responses for all the items in the scale
#'
#'
#' @export
#'
#' @references
#' Kreitchmann, R. S., Abad, F. J., Ponsoda, V., Nieto, M. D., & Morillo, D. (2019) "Controlling for response biases in self-report scales" <doi:10.3389/fpsyg.2019.02309>
#' Furnham, A. (1986) "Response bias, social desirability and dissimulation" <doi:10.1016/0191-8869(86)90014-0>
#'
#' @examples
#' data <- data.frame(
#'     Q1 = c(1, 2, 1, 2),
#'     Q2 = c(2, 1, 2, 1),
#'     Q3 = c(1, 2, 1, 2),
#'     Q4 = c(2, 1, 2, 1)
#' )
#' pattern.as(data, 1:4)



# Function to identify increasing responses
pattern.as <- function(data, cols) {
  scale_data <- data[, cols, drop = FALSE]
  increasing <- apply(scale_data, 1, function(row) {
    all(diff(row) > 0)
  })
  result <- scale_data[increasing, , drop = FALSE]
  list(
    participants = which(increasing),
    responses = result
  )
}

Try the pattern.checks package in your browser

Any scripts or data that you put into this service are public.

pattern.checks documentation built on April 3, 2025, 9:22 p.m.