#' @title {Scoring the Weight Bias Internalization Scale (WBIS)}
#' @description \emph{
#' The WBIS is a 11-item instrument for measuring the extent to which
#' overweight individuals think of themselves in terms of prevalent
#' negative stereotypes about overweight and overweight individuals.
#' Respondents can express their level of agreement on a 7-point Likert scale
#' ranging from 'strongly disagree' (1) to 'strongly agree' (7).
#' Items 1 and 9 need to be scored reversely.
#' }
#' @details
#' \itemize{
#' \item \code{Number of items:} {11}
#' \item \code{Item range:} {1 to 7}
#' \item \code{Reverse items:} {1, 9}
#' \item \code{Score range:} {11 to 77}
#' \item \code{Cut-off-values:} {none}
#' \item \code{Minimal clinically important difference:} {none}
#' \item \code{If more than 2 items have not been answered, then the total mean score is not calculated.}
#' }
#' @references
#' Durso, Latner (2008) (\url{https://doi.org/10.1038/oby.2008.448})
#'
#' Hilbert et al. (2014) (\url{https://doi.org/10.1371/journal.pone.0086303})
#' @return The function returns 2 variables:
#' \itemize{
#' \item \code{nvalid.wbis:} Number of valid values (MAX=11)
#' \item \code{score.wbis:} WBIS Score
#' }
#' @examples
#' \dontrun{
#' library(dplyr)
#' items.wbis <- paste0("WBIS_", seq(1, 11, 1))
#' scoring_wbis(mydata, items = items.wbis, reverse = c(1, 9))
#' }
#' @param data a \code{\link{data.frame}} containing the WBIS items
#' orderd from 1 to 11
#' @param items A character vector with the WBIS item names ordered from 1 to 11,
#' or a numeric vector indicating the column numbers of the WBIS 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 9.
#' @param digits Integer of length one: value to round to. No rounding by default.
#' @param reverse items to be scored reversely. These items can be specified either by name or by index. Default: 1, 9
#' @export
scoring_wbis <- function(data, items = 1:11, keep = TRUE, nvalid = 9, digits = NULL, reverse = c(1, 9)) {
library(dplyr, warn.conflicts = FALSE)
if (min(data[, items], na.rm = T) < 1) {
stop("Minimum possible value for WBIS items is 1")
} else if (max(data[, items], na.rm = T) > 7) {
stop("Maximum possible value for WBIS items is 7")
}
# check for number of specified items
if (length(items) != 11) {
stop("Number of items must be 11!")
}
items <- items
items.rev <- items[reverse]
data <- data %>%
mutate_at(vars(items.rev), list(~ 8 - .)) %>%
mutate(
nvalid.wbis = rowSums(!is.na(select(., items))),
mean.temp = round(rowSums(select(., items), na.rm = TRUE) / nvalid.wbis)
) %>%
mutate_at(
vars(items),
list(~ ifelse(is.na(.), mean.temp, .))
) %>%
mutate(
score.temp = rowSums(select(., items), na.rm = TRUE),
score.wbis = ifelse(nvalid.wbis >= nvalid, score.temp, NA)
) %>%
select(-mean.temp, -score.temp)
data
# Keep single items and nvalid variables
if (keep == FALSE) {
data <- data %>% select(-items, -nvalid.wbis)
} else {
data <- data
}
# Rounding
if (is.numeric(digits) == TRUE) {
data <- data %>% mutate_at(vars(score.wbis), list(~ round(., digits)))
} else {
data <- data
}
data
}
NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.