score: Observed Unweighted Scoring of a Set of Variables/Items

Description Usage Arguments Value See Also Examples

View source: R/quest_functions.R

Description

score calculates observed unweighted scores across a set 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. data[vrb.nm] is coerced to a matrix before scoring. If the coercion leads to a character matrix, an error is returned.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
score(
  data,
  vrb.nm,
  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

character vector of colnames in data specifying the set of variables/items.

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).

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).

inclusive

logical vector of length 1 specifying whether the score 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] (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) data[vrb.nm] 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 data[vrb.nm] should be standardized before scoring.

std.score

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

Value

numeric vector of the mean/sum of each row or NA if the frequency of observed values is less than (or equal to) ov.min. The names are the rownames of data.

See Also

scores rowMeans_if rowSums_if scoreItems

Examples

1
2
3
4
5
score(data = attitude, vrb.nm = c("complaints","privileges","learning","raises"))
score(data = attitude, vrb.nm = c("complaints","privileges","learning","raises"),
   std = TRUE) # standardized scoring
score(data = airquality, vrb.nm = c("Ozone","Solar.R","Temp"),
   ov.min = 0.75) # conditional on observed values

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to score in quest...