Skip to contents

Object containing scale or factor specification data. It describes the scale or factor, with regard to which items from the source data are part of it, which need to be summed with reverse scoring, and how to handle NAs. To be used with sum_items_to_scale() function to preprocess item data.

Usage

ScaleSpec(
  name,
  item_names,
  min,
  max,
  reverse = character(0),
  na_strategy = c("asis", "mean", "median", "mode"),
  na_value = as.integer(NA),
  na_value_custom
)

# S3 method for ScaleSpec
print(x, ...)

# S3 method for ScaleSpec
summary(object, ...)

Arguments

name

character with name of the scale/factor

item_names

character vector containing names of the items that the scale/factor consists of.

min, max

integer containing the default minimal/maximal value that the answer to the item can be scored as.

reverse

character vector containing names of the items that need to be reversed during scale/factor summing. Reversed using the default "min" and "max" values.

na_strategy

character vector specifying which strategy should be taken during filling of NA. Defaults to "asis" and, other options are "mean", "median" and "mode". Strategies are explained in the details section.

na_value

integer value to be input in missing values as default. Defaults to as.integer(NA).

na_value_custom

if there are any need for specific questions be gives specific values in place of NAs, provide a named integer vector there. Names should be the names of the questons.

x

a ScaleSpec object

...

further arguments passed to or from other methods.

object

a ScaleSpec object

Value

object of ScaleSpec class

data.frame of item names, if they are reversed, and custom NA value if available, invisibly

Details

NA imputation

it specifies how NA values should be treated during sum_items_to_scale() function run. asis strategy is literal: the values specified in na_value or na_value_custom will be used without any changes. mean, median and mode are functional strategies. They work on a rowwise basis, so the appropriate value for every observation will be used. If there are no values provided to check for the mean, median or mode, the value provided in na_value or na_value_custom will be used. The values of mean and median will be rounded before imputation.

Order of operations

  • item reversion

  • functional NAs imputation

  • literal NAs imputation

See also

Other item preprocessing functions: CombScaleSpec(), sum_items_to_scale()

Examples

# simple scale specification

simple_scaleSpec <- ScaleSpec(
  name = "simple",
  # scale consists of 5 items
  item_names = c("item_1", "item_2", "item_3", "item_4", "item_5"),
  # item scores can take range of values: 1-5
  min = 1,
  max = 5,
  # item 2 and 5 need to be reversed
  reverse = c("item_2", "item_5"))

print(simple_scaleSpec)
#> <ScaleSpec>: simple
#> No. items: 5 [2 reversed]

# scale specification with literal NA imputation strategy 

asis_scaleSpec <- ScaleSpec(
  name = "w_asis",
  item_names = c("item_1", "item_2", "item_3", "item_4", "item_5"),
  min = 1,
  max = 5,
  reverse = "item_2",
  # na values by default will be filled with `3`
  na_value = 3,
  # except for item_4, where they will be filled with `2`
  na_value_custom = c(item_4 = 2)
)

print(asis_scaleSpec)
#> <ScaleSpec>: w_asis
#> No. items: 5 [1 reversed]

# scale specification with functional NA imputation strategy

func_scaleSpec <- ScaleSpec(
  name = "w_func",
  item_names = c("item_1", "item_2", "item_3", "item_4", "item_5"),
  min = 1,
  max = 5,
  reverse = "item_2",
  # strategies available are 'mean', 'median' and 'mode'
  na_strategy = "mean"
)

print(func_scaleSpec)
#> <ScaleSpec>: w_func
#> No. items: 5 [1 reversed]