R/eq5d3l.R

Defines functions scoring_eq5d3l

Documented in scoring_eq5d3l

#' @title {Scoring the European Quality of Life Five Dimension Three Level Scale Questionnaire (EQ-5D-3L)}
#' @description {\emph{EQ-5D is a standardised measure of health status developed by the EuroQol Group
#' to provide a simple, generic measure of health for clinical and economic appraisal. [...]
#' The EQ-5D-3L descriptive system comprises the following five dimensions, each describing
#' a different aspect of health: MOBILITY,  SELF-CARE, USUAL ACTIVITIES, PAIN / DISCOMFORT
#' and ANXIETY / DEPRESSION.} (EQ-5D User Guide)}
#' @note {The scoring algorithm uses the TTO value set for Germany}
#' @details
#' \itemize{
#' \item \code{Number of items:} {5}
#' \item \code{Item range:} {1 to 3}
#' \item \code{Reverse items:} {none}
#' \item \code{Score range:} {0 to 1}
#' \item \code{Cut-off-values:} {none}
#' \item \code{Minimal clinically important difference:} {none}
#' \item \code{Treatment of missing values:}
#' {The Index Score is calculated if none of the five items is missing.}
#' }
#' @references
#' Janssen et al (2012) (\url{https://dx.doi.org/10.1007/s11136-012-0322-4})
#'
#' EQ-5D User Guide (\url{https://euroqol.org/wp-content/uploads/2018/12/EQ-5D-3L-User-Guide_version-6.0.pdf})
#' @return The function returns 2 variables:
#' \itemize{
#'  \item \code{nvalid.eq5d3l:} Number of valid values (MAX=5)
#'  \item \code{score.eq5d3l:} EQ-5D-3L Index Score (TTO method)
#' }
#' @examples
#' \dontrun{
#' library(dplyr)
#' items.eq5d3l <- paste0("eq5d3l_", seq(1, 5, 1))
#' scoring_eq5d3l(mydata, items = items.eq5d3l)
#' }
#' @param data a \code{\link{data.frame}} containing the EQ-5D-3L items
#' orderd from 1 to 5
#' @param items A character vector with the EQ-5D-3L item names ordered from 1 to 5,
#' or a numeric vector indicating the column numbers of the EQ-5D-3L 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 5.
#' @param digits Integer of length one: value to round to. No rounding by default.
#' @export
scoring_eq5d3l <- function(data, items = 1:5, keep = TRUE, nvalid = 5, digits = NULL) {
  library(dplyr, warn.conflicts = FALSE)
  if (min(data[, items], na.rm = T) < 1) {
    stop("Minimum possible value for EQ-5D-3L items is 1")
  } else if (max(data[, items], na.rm = T) > 3) {
    stop("Maximum possible value for EQ-5D-3L items is 3")
  }
  # check for number of specified items
  if (length(items) != 5) {
    stop("Number of items must be 5!")
  }
  items <- items
  item.1 <- items[1]
  item.2 <- items[2]
  item.3 <- items[3]
  item.4 <- items[4]
  item.5 <- items[5]

  data <- data %>%
    mutate(eq5d3l.01.temp = rowSums(select(., item.1)),
           eq5d3l.02.temp = rowSums(select(., item.2)),
           eq5d3l.03.temp = rowSums(select(., item.3)),
           eq5d3l.04.temp = rowSums(select(., item.4)),
           eq5d3l.05.temp = rowSums(select(., item.5)),
           nvalid.eq5d3l = rowSums(!is.na(select(., items))),
           ) %>%
    mutate(
      score.eq5d3l = 1,
      score.eq5d3l = case_when(
        eq5d3l.01.temp == 2 ~ score.eq5d3l - 0.099,
        eq5d3l.01.temp == 3 ~ score.eq5d3l - 0.329,
        TRUE ~ score.eq5d3l,
      ),
      score.eq5d3l = case_when(
        eq5d3l.02.temp == 2 ~ score.eq5d3l - 0.087,
        eq5d3l.02.temp == 3 ~ score.eq5d3l - 0.174,
        TRUE ~ score.eq5d3l,
      ),
      score.eq5d3l = case_when(
        eq5d3l.03.temp == 2 ~ score.eq5d3l - 0,
        eq5d3l.03.temp == 3 ~ score.eq5d3l - 0,
        TRUE ~ score.eq5d3l,
      ),
      score.eq5d3l = case_when(
        eq5d3l.04.temp == 2 ~ score.eq5d3l - 0.112,
        eq5d3l.04.temp == 3 ~ score.eq5d3l - 0.315,
        TRUE ~ score.eq5d3l,
      ),
      score.eq5d3l = case_when(
        eq5d3l.05.temp == 2 ~ score.eq5d3l - 0,
        eq5d3l.05.temp == 3 ~ score.eq5d3l - 0.065,
        TRUE ~ score.eq5d3l,
      ),
      score.eq5d3l = if_else(apply(select(., items), 1, max, na.rm = TRUE) >= 2, score.eq5d3l - 0.001, score.eq5d3l, as.numeric(NA)),
      score.eq5d3l = if_else(apply(select(., items), 1, max, na.rm = TRUE) == 3, score.eq5d3l - 0.323, score.eq5d3l, as.numeric(NA)),
      score.eq5d3l = if_else(nvalid.eq5d3l < 5, as.numeric(NA), score.eq5d3l)
    ) %>%
    select(-ends_with("temp"))
    # Keep single items and nvalid variables
    if (keep == FALSE) {
      data <- data %>% select(-items, -nvalid.eq5d3l)
    } else {
      data <- data
    }
    # Rounding
    if (is.numeric(digits) == TRUE) {
      data <- data %>% mutate_at(vars(score.eq5d3l), list(~ round(., digits)))
    } else {
      data <- data
    }
    data
}
NULL
nrkoehler/qscorer documentation built on April 5, 2020, 3:09 a.m.