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:
correctedcorrected version of
x
modifiedlogical,
TRUE
when any of the elements ofx
have been changedcorrected_value()
returns the corrected value if passed the result ofcorrect_sign()
is_corrected()
returnsTRUE
if a modifications was made if passed the result ofcorrect_sign()
,FALSE
otherwise
These components can be extracted with the functions corrected_value
and is_corrected
.
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')