library(wbpip)
#> Warning: replacing previous import 'collapse::fdroplevels' by
#> 'data.table::fdroplevels' when loading 'wbpip'
Load and prep data
data("md_ABC_2000_income")
# Basic cleaning operation (remove missings, negative values, etc.)
df <- wbpip:::md_clean_data(md_ABC_2000_income,
welfare = "welfare",
weight = "weight")
#> ℹ Data has been sorted by variable "welfare"
df <- df$data
# Turn welfare vector to monthly values
# All computations assume monthly welfare values
df$welfare <- df$welfare / 12
Compute PIP poverty stats
# Poverty line needs to be expressed in monthly international dollar values
# The conversion from daily to monthly values needs to happen at a higher level
# in the functions call stack for efficiency purposes
poverty_line <- 1.9 * 365 / 12
# default_ppp
# This will need to be provided directly by a potential end-users
# For production use: This value will be fed directly to the function depending
# on the requested country / year.
ppp_value <- 58.16
# requested mean
# This is the survey mean in internationl dollars
# The conversion from LCU to international dollars needs to happen at a higher
# level in the fucntion call stack for efficiency purposes.
# This parameter is also used for interpolation computation to query the welfare
# distribution using a different mean.
welfare_mean <- 225
out <- wbpip:::md_compute_pip_stats(welfare = df$welfare,
population = df$weight,
povline = poverty_line,
default_ppp = ppp_value,
requested_mean = welfare_mean)
out
#> $poverty_line
#> [1] 57.79167
#>
#> $mean
#> [1] 225
#>
#> $median
#> [1] 132.9027
#>
#> $headcount
#> [1] 0.1418472
#>
#> $poverty_gap
#> [1] 0.051882
#>
#> $poverty_severity
#> [1] 0.02683585
#>
#> $watts
#> [1] 0.07785021
#>
#> $gini
#> [1] 0.5147999
#>
#> $mld
#> [1] 0.473487
#>
#> $polarization
#> [1] 0.469777
#>
#> $deciles
#> [1] 0.01343078 0.02616405 0.03535142 0.04437412 0.05416520 0.06553887
#> [7] 0.08320632 0.10988798 0.15703608 0.41084518