R/gses.R

Defines functions scoring_gses

Documented in scoring_gses

#' @title {Scoring the General Self-Efficacy Scale (GSES)}
#' @description \emph{The General Self-Efficacy Scale is a 10-item psychometric scale
#' that is designed to assess optimistic self-beliefs to cope with a variety of
#' difficult demands in life. The scale has been originally developed in German
#' by Matthias Jerusalem and Ralf Schwarzer in 1981.} (\url{http://userpage.fu-berlin.de/health/selfscal.htm})
#' @details
#' \itemize{
#' \item \code{Number of items:} {10}
#' \item \code{Item range:} {1 to 4}
#' \item \code{Reverse items:} {none}
#' \item \code{Score range:} {10 to 40}
#' \item \code{Cut-off-values:} {none}
#' \item \code{Minimal clinically important difference:} {none}
#' \item \code{Treatment of missing values:}
#' {"Our rule of thumb is to calculate a score as long as no more than
#' three items on the ten-item scale are missing." (FAQ Document)
#' }
#' }
#' @references
#' Schwarzer, R. & Jerusalem, M. (Hrsg.) (1999). Skalen zur Erfassung von  Lehrer- und Schuelermerkmalen. Dokumentation der psychometrischen Verfahren im Rahmen der Wissenschaftlichen Begleitung des Modellversuchs Selbstwirksame Schulen. Berlin: FU Berlin
#'
#' Skala zur Allgemeinen Selbstwirksamkeitserwartung (SWE) (\url{http://psymet03.sowi.uni-mainz.de/download/Lehre/SS2010/SPSSKurs/Termin_1/SWE_Beschreibung.pdf/})
#'
#' FAQ (\url{http://userpage.fu-berlin.de/health/faq_gse.pdf})
#' @return The function returns 2 variables:
#' \itemize{
#'  \item \code{nvalid.gses:} Number of valid values (MAX=10)
#'  \item \code{score.gses:} GSES Score
#' }
#' @examples
#' \dontrun{
#' library(dplyr)
#' items.gses <- paste0("GSES_", seq(1, 10, 1))
#' scoring_gses(mydata, items = items.gses)
#' }
#' @param data a \code{\link{data.frame}} containing the GSES items
#' orderd from 1 to 10
#' @param items A character vector with the GSES item names ordered from 1 to 10,
#' or a numeric vector indicating the column numbers of the GSES items in \code{data}.
#' @param keep Logical, whether to keep the single items and  whether to return variables containing
#' the number of non-missing items on each scale for each respondent. The default is TRUE.
#' @param nvalid A numeric value indicating the number of non-missing items required for score
#' calculations. The default is 7.
#' @param digits Integer of length one: value to round to. No rounding by default.
#' @export
scoring_gses <- function(data, items = 1:10, keep = TRUE, nvalid = 7, digits = NULL) {
  library(dplyr, warn.conflicts = FALSE)
  if (min(data[, items], na.rm = T) < 1) {
    stop("Minimum possible value for GSES items is 1")
  } else if (max(data[, items], na.rm = T) > 4) {
    stop("Maximum possible value for GSES items is 4")
  }
  # check for number of specified items
  if (length(items) != 10) {
    stop("Number of items must be 10!")
  }
  items <- items
  data <- data %>%
    mutate(
      nvalid.gses = rowSums(!is.na(select(., items))),
      mean.temp = round(rowSums(select(., items), na.rm = TRUE) / nvalid.gses)
    ) %>%
    mutate_at(
      vars(items),
      list(~ ifelse(is.na(.), mean.temp, .))
    ) %>%
    mutate(
      score.temp = rowSums(select(., items), na.rm = TRUE),
      score.gses = ifelse(nvalid.gses >= nvalid, score.temp, NA)
    ) %>%
    select(-mean.temp, -score.temp)
  data
  # Keep single items and nvalid variables
  if (keep == FALSE) {
    data <- data %>% select(-items, -nvalid.gses)
  } else {
    data <- data
  }
  # Rounding
  if (is.numeric(digits) == TRUE) {
    data <- data %>% mutate_at(vars(score.gses), list(~ round(., digits)))
  } else {
    data <- data
  }
  data
}
NULL
nrkoehler/qscorer documentation built on April 5, 2020, 3:09 a.m.