#' @title {Scoring the Social Support Questionnaire, short form (F-SozU-K-7)}
#' @description \emph{
#' The F-SozU-K-7 is a 7-item scale designed to measure perceived social support.
#' Items are Likert-scaled (1 to 5).
#' A total mean score ranging from 1 to 5 may be calculated.
#' }
#' @details
#' \itemize{
#' \item \code{Number of items:} {7}
#' \item \code{Item range:} {1 to 5}
#' \item \code{Reverse items:} {none}
#' \item \code{Score range:} {1 to 5}
#' \item \code{Cut-off-values:} {none}
#' \item \code{Minimal clinically important difference:} {none}
#' \item \code{Treatment of missing values:}
#' {If at least one item is missing, that F-SozU-K-7 score must not be calculated.}
#' }
#' @references
#' Sommer, Fydrich (1991) [Development and validation of a questionnaire on social support]. Diagnostica 37 (2): 160--178
#' @return The function returns 2 variables:
#' \itemize{
#' \item \code{nvalid.fsozuk7:} Number of valid values (MAX=7)
#' \item \code{score.fsozuk7:} F-SozU-K-7 Score
#' }
#' @examples
#' \dontrun{
#' library(dplyr)
#' items.fsozu <- paste0("FSOZU_", seq(1, 7, 1))
#' scoring_fsozuk7(mydata, items = items.fsozu)
#' }
#' @param data a \code{\link{data.frame}} containing the F-SozU-K-7 items
#' orderd from 1 to 7
#' @param items A character vector with the F-SozU-K-7 item names ordered from 1 to 7,
#' or a numeric vector indicating the column numbers of the F-SozU-K-7 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 6.
#' @param digits Integer of length one: value to round to. No rounding by default.
#' @export
scoring_fsozuk7 <- function(data, items = 1:7, keep = TRUE, nvalid = 6, digits = NULL) {
library(dplyr, warn.conflicts = FALSE)
if (min(data[, items], na.rm = T) < 1) {
stop("Minimum possible value for F-SozU-K-7 items is 1")
} else if (max(data[, items], na.rm = T) > 5) {
stop("Maximum possible value for F-SozU-K-7 items is 5")
}
# check for number of specified items
if (length(items) != 7) {
stop("Number of items must be 7!")
}
items <- items
data <- data %>%
mutate(
nvalid.fsozuk7 = rowSums(!is.na(select(., items))),
score.fsozuk7 = rowSums(select(., items), na.rm = FALSE)
)
# Keep single items and nvalid variables
if (keep == FALSE) {
data <- data %>% select(-items, -nvalid.fsozuk7)
} else {
data <- data
}
# Rounding
if (is.numeric(digits) == TRUE) {
data <- data %>% mutate_at(vars(score.fsozuk7), 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.