correct_sign: Corrects negative values in the health variable

View source: R/correct-sign.R

correctSignR 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)

Arguments

x

a numeric vector, typically representing health.

shift

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

Value

Returns a list with 2 components:

corrected

corrected version of x

modified

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

These components can be extracted with the functions correctedValue and isCorrected.

Author(s)

Peter Konings

Examples

data(nigeria)

nigeria$zscore.shifted <- corrected_value(correct_sign(nigeria$zscore, shift = TRUE))
nigeria$zscore.imputed <- corrected_value(correct_sign(nigeria$zscore, shift = FALSE))

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

brechtdv/rineq documentation built on Feb. 21, 2024, 2:18 p.m.