#' Calculate raw score for continuous performance test
#'
#' This function calculates raw score from json recording of "cpt" test.
#'
#' @param data Raw data of class \code{data.frame}.
#' @param ... Other input argument for future expansion.
#' @return The raw score calculated of \code{double} type.
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#' @export
cpt <- function(data, ...) {
if (!utils::hasName(data, "ACC")) {
warning("Accuracy (`ACC`) variable is required.")
return(NA_real_)
}
if (!utils::hasName(data, "Type")) {
warning("Trial type (`Type`) variable is required.")
return(NA_real_)
}
data %>%
dplyr::mutate(is_target = ifelse(.data$Type == "Target", "Y", "N")) %>%
dplyr::group_by(.data$is_target) %>%
dplyr::summarise(pc = mean(.data$ACC)) %>%
tidyr::pivot_wider(names_from = "is_target", values_from = "pc") %>%
dplyr::mutate(score = .data$Y + .data$N - 1) %>%
dplyr::pull("score")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.