correct_sign {rineq} | R Documentation |
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)
Arguments
x |
A numeric vector, typically representing health. |
shift |
If |
Value
correct_sign()
returns a list with 2 components:
-
corrected
: corrected version ofx
-
modified
: logical,TRUE
when any of the elements ofx
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()
,
Functions
-
corrected_value()
: Return the corrected value -
is_corrected()
: Check if the sign was corrected
Author(s)
Peter Konings
Examples
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')