Learn R Programming

rineq (version 0.3.0)

correct_sign: Corrects negative values in the health variable

Description

The Relative Concentration Index is not bonded between \([-1,1]\) if the health variable contains both negative and positive values. This function corrects for this either by imputing a value of 0 for all negative values or by subtracting the minimum value.

Usage

correct_sign(x, shift = TRUE)

corrected_value(x)

is_corrected(x)

Value

correct_sign() returns a list with 2 components:

  • corrected: corrected version of x

  • modified: logical, TRUE when any of the elements of x have been changed

corrected_value(): returns the corrected value if passed the result of `correct_sign().

is_corrected(): returns TRUE if a modifications was made and FALSE otherwise. Takes as argument the result of correct_sign(),

Arguments

x

A numeric vector, typically representing health.

shift

If FALSE (the default), 0 is imputed for all negative values in x. If TRUE the minimum value of x is subtracted from it.

Functions

  • corrected_value(): Return the corrected value

  • is_corrected(): Check if the sign was corrected

Author

Peter Konings

Examples

Run this code
data("housing")

# standardize & normalize bmi, will introduce negative values
housing$bmi.std <- (housing$bmi - mean(housing$bmi))/ sd(housing$bmi)

housing$bmi.std.shifted <- corrected_value(correct_sign(housing$bmi.std, shift = TRUE))
housing$bmi.std.imputed <- corrected_value(correct_sign(housing$bmi.std, shift = FALSE))

## compare the effect of both methods
plot(density(housing$bmi.std, na.rm = TRUE))
points(density(housing$bmi.std.shifted, na.rm = TRUE), col = 'blue')
points(density(housing$bmi.std.imputed, na.rm = TRUE), col = 'green')

Run the code above in your browser using DataLab