R/iwqol.R

Defines functions scoring_iwqoll

Documented in scoring_iwqoll

#' @title {Scoring the Impact of Weight on Quality of Life-Lite Questionnaire (IWQOL-Lite)}
#' @description {\emph{The  IWQOL is a self-report instrument specifically  developed
#' to  assess  the  effect  of  obesity  on quality-of-life. IWQOL-Lite is a short form
#' containing 31 items. Scale scores are obtained by adding item scores, and the total score
#' is obtained by adding scale scores. Higher scores indicate poorer quality of life.} (Kolotin et al. 2001)}
#' @details {
#' \itemize{
#' \item \code{Number of items:} {31}
#' \item \code{Item range:} {1 to 5}
#' \item \code{Reverse items:} {none}
#' \item \code{Score range:}
#'      \itemize{
#'      \item \code{Physical Function} {11 to 55}
#'      \item \code{Self-esteem} {7 to 35}
#'      \item \code{Sexual Life} {4 to 20}
#'      \item \code{Public Distress} {5 to 25}
#'      \item \code{Work} {4 to 20}
#'      \item \code{Total Score} {31 to 155}
#'              }
#' \item \code{Cut-off-values:} {none}
#' \item \code{Minimal clinically important difference:} {none}
#' \item \code{Treatment of missing values:} {Number of valid items:
#'      \itemize{
#'      \item \code{Physical Function} {6 of 11}
#'      \item \code{Self-esteem} {4 of 7}
#'      \item \code{Sexual Life} {2 of 4}
#'      \item \code{Public Distress} {3 of 5}
#'      \item \code{Work} {2 of 4}
#'      \item \code{Total Score} {24 of 31}
#'             }}}}
#' @references
#' Kolotkin et al. 2001 (\url{http://doi.wiley.com/10.1038/oby.2001.13})
#'
#' Kolotkin et al. 2002 (\url{https://doi.org/10.1023/a:1015081805439})
#' @return The function returns 12 variables:
#' \itemize{
#'  \item \code{nvalid.iwqol.pf:} Number of valid values of Physical Function scale (MAX=11)
#'  \item \code{nvalid.iwqol.se:} Number of valid values of Self-esteem scale (MAX=7)
#'  \item \code{nvalid.iwqol.sl:} Number of valid values of Sexual Life scale (MAX=4)
#'  \item \code{nvalid.iwqol.pd:} Number of valid values of Public Distress scale (MAX=5)
#'  \item \code{nvalid.iwqol.wo:} Number of valid values of Work scale (MAX=4)
#'  \item \code{nvalid.iwqol.ts:} Number of valid values of Total scale (MAX=31)
#'  \item \code{score.iwqol.pf:} IWQOL Physical Function Score
#'  \item \code{score.iwqol.se:} IWQOL Self-esteem Score
#'  \item \code{score.iwqol.sl:} IWQOL Sexual Life Score
#'  \item \code{score.iwqol.pd:} IWQOL Public Distress Score
#'  \item \code{score.iwqol.wo:} IWQOL Work Score
#'  \item \code{score.iwqol.ts:} IWQOL Total Score
##' }
#' @examples
#' \dontrun{
#' library(dplyr)
#' items.iwqoll <- paste0("IWQOLL_", seq(1, 31, 1))
#' scoring_iwqoll(mydata, items = items.iwqoll)
#' }
#' @param data a \code{\link{data.frame}} containing the IWQOL-Lite items orderd from 1 to 31.
#' The \code{\link{data.frame}} may contain further variables.
#' @param items A character vector with the IWQOL-Lite item names ordered from 1 to 31,
#' or a numeric vector indicating the column numbers of the IWQOL-Lite 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 named list indicating the number of non-missing items required for score
#' calculations. The defaults are:
#' \itemize{
#'  \item \code{physical = 6} {(Physical Function)}
#'  \item \code{self = 4} {(Self-esteem)}
#'  \item \code{sexual = 2} {(Sexual Life)}
#'  \item \code{distress = 3} {(Public Distress)}
#'  \item \code{work = 2} {(Work)}
#' }
#' @param digits Integer of length one: value to round to. No rounding by default.
#' @export
scoring_iwqoll <- function(data, items = 1:31, keep = TRUE,
                           nvalid = list(
                             physical = 6,
                             self = 4,
                             sexual = 2,
                             distress = 3,
                             work = 2
                           ),
                           digits = NULL) {
  library(dplyr, warn.conflicts = FALSE)
  if (min(data[, items], na.rm = T) < 1) {
    stop("Minimum possible value for IWQOL items is 1")
  } else if (max(data[, items], na.rm = T) > 5) {
    stop("Maximum possible value for IWQOL items is 5")
  }
  # check for number of specified items
  if (length(items) != 31) {
    stop("Number of items must be 31!")
  }
  items <- items
  items.pf <- items[1:11]
  items.se <- items[12:18]
  items.sl <- items[19:22]
  items.pd <- items[23:27]
  items.wo <- items[28:31]
  data %>%
    mutate(
      nvalid.iwqol.ts = rowSums(!is.na(select(., items))),
      nvalid.iwqol.pf = rowSums(!is.na(select(., items.pf))),
      nvalid.iwqol.se = rowSums(!is.na(select(., items.se))),
      nvalid.iwqol.sl = rowSums(!is.na(select(., items.sl))),
      nvalid.iwqol.pd = rowSums(!is.na(select(., items.pd))),
      nvalid.iwqol.wo = rowSums(!is.na(select(., items.wo))),
      mean.pf = round(rowSums(select(., items.pf), na.rm = TRUE) / nvalid.iwqol.pf),
      mean.se = round(rowSums(select(., items.se), na.rm = TRUE) / nvalid.iwqol.se),
      mean.sl = round(rowSums(select(., items.sl), na.rm = TRUE) / nvalid.iwqol.sl),
      mean.pd = round(rowSums(select(., items.pd), na.rm = TRUE) / nvalid.iwqol.pd),
      mean.wo = round(rowSums(select(., items.wo), na.rm = TRUE) / nvalid.iwqol.wo),
    ) %>%
    mutate_at(vars(items.pf), list(~ ifelse(is.na(.), round(mean.pf), .))) %>%
    mutate_at(vars(items.se), list(~ ifelse(is.na(.), round(mean.se), .))) %>%
    mutate_at(vars(items.sl), list(~ ifelse(is.na(.), round(mean.sl), .))) %>%
    mutate_at(vars(items.pd), list(~ ifelse(is.na(.), round(mean.pd), .))) %>%
    mutate_at(vars(items.wo), list(~ ifelse(is.na(.), round(mean.wo), .))) %>%
    mutate(
      score.iwqol.pf = rowSums(select(., items[1:11]), na.rm = TRUE),
      score.iwqol.pf = ifelse(nvalid.iwqol.pf >= 6, score.iwqol.pf, NA),
      score.iwqol.se = rowSums(select(., items[12:18]), na.rm = TRUE),
      score.iwqol.se = ifelse(nvalid.iwqol.se >= 4, score.iwqol.se, NA),
      score.iwqol.sl = rowSums(select(., items[19:22]), na.rm = TRUE),
      score.iwqol.sl = ifelse(nvalid.iwqol.sl >= 2, score.iwqol.sl, NA),
      score.iwqol.pd = rowSums(select(., items[23:27]), na.rm = TRUE),
      score.iwqol.pd = ifelse(nvalid.iwqol.pd >= 3, score.iwqol.pd, NA),
      score.iwqol.wo = rowSums(select(., items[28:31]), na.rm = TRUE),
      score.iwqol.wo = ifelse(nvalid.iwqol.wo >= 2, score.iwqol.wo, NA)
    ) %>%
    mutate(score.iwqol.ts = score.iwqol.pf + score.iwqol.se + score.iwqol.sl +
      score.iwqol.pd + score.iwqol.wo) %>%
    select(-starts_with("mean."))
}
NULL
nrkoehler/qscorer documentation built on April 5, 2020, 3:09 a.m.