Skip to contents

Computes case weights adding to one for response variables of these types:

  • numeric binomial (1 and 0).

  • logical (TRUE and FALSE): converted to numeric internally.

  • categorical (character or factor)

Values NA, Inf, -Inf, and NaN are invalid for numeric and logical variables and will result in errors. For categorical variables, these are converted to their respective categories ("NA", "Inf", "-Inf", and "NaN") with their assigned case weights.

All returned weights sum to one.

Usage

case_weights(x = NULL, ...)

Arguments

x

(required, integer, character, or factor vector) Values of a binomial, categorical, or factor variable. Default: NULL

...

(optional) Internal args (e.g. function_name for validate_arg_function_name, a precomputed correlation matrix m, or cross-validation args for preference_order).

Value

numeric vector: case weights

See also

Examples

 #numeric vector
 y <- case_weights(
   x = c(0, 0, 1, 1)
   )

 #logical vector
 y <- case_weights(
   x = c(TRUE, TRUE, FALSE, FALSE)
   )

 #character vector
 y <- case_weights(
   x = c("a", "a", "b", "c")
   )