Skip to contents

Creates a scale definition that groups items and specifies how composite scores are computed. The scale carries scoring rules used by score_scales() and measurement structure used by sframe_reliability_results(), sframe_item_results(), and sframe_syntax_cfa().

Usage

sframe_scale(
  id,
  label,
  items,
  method = c("mean", "sum"),
  min_valid = NULL,
  reverse_items = NULL,
  weights = NULL
)

Arguments

id

Character. A unique identifier for this scale. Referenced in the scale_id argument of sframe_item().

label

Character. A human-readable name for the scale, used in reports and codebooks.

items

Character vector. The id values of items that belong to this scale, each listed once. Order controls presentation in reports, while scoring uses the same item IDs regardless of order. Items themselves are passed to sframe_instrument() as separate components.

method

Character. Scoring method. Either "mean" (default) or "sum".

min_valid

Integer or NULL. The minimum number of answered items required to compute a score for a respondent, a whole number from 1 to the number of items. When NULL, every item must be answered. An item whose column is absent from the data counts as unanswered. Used by score_scales(). With method = "sum", a respondent who answered fewer than every item but at least min_valid gets a prorated sum: the mean of the answered items times the number of items (weighted, the weighted mean times the sum of the weights), so the score stays on the full scale's range. Before 0.4.3 an unanswered item counted as 0.

reverse_items

Character vector or NULL. A subset of items that this scale reverse-codes. Reversal applies within this scale only, so the same item can be reversed in one scale and scored as answered in another. An item can also be flagged with reverse = TRUE in sframe_item(), which reverses it within the scale named by its scale_id. A reversed item needs declared response bounds, from a numeric choice set, slider limits or a rating maximum.

weights

Numeric vector or NULL. Item weights for weighted scoring, one positive finite number per item, in the order of items. score_scales() applies the weights to either method = "mean" or method = "sum".

Value

An object of class sf_scale (a named list).

Examples

sat_scale <- sframe_scale(
  id            = "satisfaction",
  label         = "Customer Satisfaction",
  items         = c("sat_overall", "sat_speed", "sat_quality"),
  method        = "mean",
  min_valid     = 2,
  reverse_items = NULL
)
sat_scale