Skip to contents

Compute the Wolfson polarization index for microdata.

Usage

pipmd_polarization(
  welfare,
  weight = rep(1, length = length(welfare)),
  gini = NULL,
  mean = NULL,
  median = NULL,
  format = c("dt", "list", "atomic")
)

Arguments

welfare

welfare vector

weight

population weight vector

gini

numeric: gini coefficient. If NULL (default) then uses pipmd_gini to calculate the gini.

mean

numeric: weighted welfare mean. Default is NULL.

median

numeric: weighted welfare mean. Default is NULL.

format

character: "dt", "list", "atomic", giving the format of the output

Value

Returns a data.table and data.frame object with two variables: indicator and value. Check format argument to change the output format.

Details

Given a vector of income or consumption values and their respective weights pipmd_polarization() computes the Wolfson polarization index.

Examples

# Example 1: Basic polarization calculation with default settings
pipmd_polarization(welfare = pip_md_s$welfare,
                   weight = pip_md_s$weight)
#>       indicator     value
#>          <char>     <num>
#> 1: polarization 0.4301155

# Example 2: Specifying Gini coefficient, mean, and median
custom_gini <- pipmd_gini(welfare = pip_md_s$welfare,
                          weight = pip_md_s$weight,
                          format = "atomic")
custom_mean <- mean(pip_md_s$welfare)
custom_median <- median(pip_md_s$welfare)
pipmd_polarization(welfare = pip_md_s$welfare,
                   weight = pip_md_s$weight,
                   gini = custom_gini,
                   mean = custom_mean,
                   median = custom_median,
                   format = "list")
#> $polarization
#> [1] 0.4038148
#> 
rm(custom_gini, custom_mean, custom_median)

# Example 3: Returning polarization index in data.table format
pipmd_polarization(welfare = pip_md_s$welfare,
                   weight = pip_md_s$weight,
                   format = "dt")
#>       indicator     value
#>          <char>     <num>
#> 1: polarization 0.4301155

# Example 4: Using equal weights (weight vector is NULL)
pipmd_polarization(welfare = pip_md_s$welfare,
                   format = "atomic")
#> polarization 
#>    0.3827663 
#> attr(,"label")
#> [1] "welfare(income of consumption)"