scores {quest}R Documentation

Observed Unweighted Scoring of Multiple Sets of Variables/Items

Description

scores calculates observed unweighted scores across multiple sets of variables/items. If a row's frequency of observed data is less than (or equal to) ov.min, then NA is returned for that row. Each set of variables/items are coerced to a matrix before scoring. If the coercion leads to a character matrix, an error is returned. This can be tested with lapply(X = vrb.nm.list, FUN = function(nm) is.character(as.matrix(data[nm]))).

Usage

scores(
  data,
  vrb.nm.list,
  avg = TRUE,
  ov.min = 1,
  prop = TRUE,
  inclusive = TRUE,
  impute = TRUE,
  std = FALSE,
  std.data = std,
  std.score = std
)

Arguments

data

data.frame or numeric/logical matrix

vrb.nm.list

list where each element is a character vector of colnames in data specifying the variables/items for that score. The names of vrb.nm.list will be the names of the scores in the return object.

avg

logical vector of length 1 specifying whether mean scores (TRUE) or sum scores (FALSE) should be created.

ov.min

minimum frequency of observed values required per row. If prop = TRUE, then this is a decimal between 0 and 1. If prop = FALSE, then this is a integer between 0 and length(vrb.nm.list[[i]]).

prop

logical vector of length 1 specifying whether ov.min should refer to the proportion of observed values (TRUE) or the count of observed values (FALSE). If the multiple sets of variables/items contain different numbers of variables, it probably makes the most sense to use the proportion of observed values (TRUE).

inclusive

logical vector of length 1 specifying whether the scores should be calculated (rather than NA) if the frequency of observed values in a row is exactly equal to ov.min.

impute

logical vector of length 1 specifying if missing values should be imputed with the mean of observed values from each row of data[vrb.nm.list[[i]] ] (i.e., row mean imputation). If TRUE (default), this will make sums over the same rows with different frequencies of missing values comparable. Note, this argument is only used when avg = FALSE since when avg = TRUE row mean imputation is always done implicitly.

std

logical vector of length 1 specifying whether 1) the variables should be standardized before scoring and 2) the score standardized after creation. This argument is for convenience as these two standardization processes are often used together. However, this argument will be overwritten by any non-default value for std.data and std.score.

std.data

logical vector of length 1 specifying whether the variables/items should be standardized before scoring.

std.score

logical vector of length 1 specifying whether the scores should be standardized after creation.

Value

data.frame of mean/sum scores with NA for any row with the frequency of observed values less than (or equal to) ov.min. The colnames are specified by names(vrb.nm.list) and rownames by row.names(data).

See Also

score rowMeans_if rowSums_if scoreItems

Examples

list_colnames <- list("first" = c("rating","complaints","privileges"),
    "second" = c("learning","raises","critical"))
scores(data = attitude, vrb.nm.list = list_colnames)
list_colnames <- list("first" = c("Ozone","Wind"),
    "second" = c("Solar.R","Temp"))
scores(data = airquality, vrb.nm.list = list_colnames, ov.min = .50,
   inclusive = FALSE) # scoring conditional on observed values

[Package quest version 0.2.0 Index]