R/meanscore.R

Defines functions meanscore

Documented in meanscore

#' Calculate raw score for speed and accuracy games
#'
#' This function calculates raw scores for tests that requires both accuracy
#' and speed. The score is calculated by get the number of correct per minute.
#'
#' @param data Raw data of class \code{data.frame}.
#' @param dur The time consumed in minute to complete the test.
#' @param ... Other input argument for future expansion.
#' @return The raw score calculated of \code{double} type.
#' @importFrom magrittr %>%
#' @export
meanscore <- function(data, dur = 3, ...) {
  vars_correct <- c("ACC", "Repetition")
  idx_var_correct <- utils::hasName(data, vars_correct)
  if (!any(idx_var_correct)) {
    warning("Variable that records correctness is required.")
    return(NA_real_)
  }
  correctness <- dplyr::pull(data, vars_correct[idx_var_correct])
  if (mean(correctness == -1) >= 0.2) {
    warning("Response rate is too low.")
    return(NA_real_)
  }
  sum(correctness == 1) / dur
}
psychelzh/dataprocr documentation built on Oct. 12, 2019, 1:50 a.m.