score_scale: Score scale calculates scale scores.

View source: R/score_scale.R

score_scaleR Documentation

Score scale calculates scale scores.

Description

Score scale calculates scale scores.

Usage

score_scale(
  data,
  filter,
  sum = FALSE,
  min_valid = 1,
  max_na = NA,
  label = NULL,
  fun = NULL,
  var_weight = NULL,
  var_recoding = NULL
)

Arguments

data

A data frame

filter

A logical expression for any dic attribute (e.g. scale == "ITRF" & subscale == "Int")

sum

If FALSE, a weighted mean function is applied for building the scores. If TRUE, a weighted sum function is applied. When argument fun is set, sum is ignored.

min_valid

Minimal number of valid values that is required for calculating the mean. A value between 0 and 1 indicates a proportion of values (e.g., 0.5 = 50 percent of values have to be valid).

max_na

Maximum number of NAs that are allowed before returning NA. A value between 0 and 1 indicates a proportion of values (e.g., 0.5 = 50 percent NAs are allowed).

label

A character string with a label for the resulting score variable. Automatically generated if label is not set.

fun

A function for calculating the score (e.g., weighted.median). See details.

var_weight

Name of the dic attribute that is applied to derive weights. Defaults to weight.

Details

If you provide your own function, the first argument of that function must take the vector of values and the second argument the weights.

Value

A data frame

Examples

dat <- apply_dic(ex_scaledic_data, ex_scaledic_dic)
# apply the default weighted mean function
score_scale(dat, scale == "rel", label = "Religious beliefs")
# apply the weighted sum function
score_scale(dat, scale == "rel", label = "Religious beliefs", sum = TRUE)
# provide an external function (here the weighted median function from the spatstat package)
score_scale(dat, scale == "rel", label = "Religious beliefs", fun = spatstat.geom::weighted.median)


jazznbass/scaledic documentation built on July 19, 2023, 12:50 a.m.