Title: | Multidimensional Poverty Index (MPI) |
---|---|
Description: | A set of easy-to-use functions for computing the Multidimensional Poverty Index (MPI). |
Authors: | Bhas Abdulsamad [aut, cre, cph]
|
Maintainer: | Bhas Abdulsamad <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2025-03-11 03:45:48 UTC |
Source: | https://github.com/yng-me/mpindex |
This function uses the Alkire-Foster (AF) counting method developed by Sabina Alkire and James Foster. It requires a deprivation profile created using the (define_deprivation
) fuction containing all indicators defined in the specification files.
compute_mpi( .data, .deprivation_profile, ..., .mpi_specs = getOption("mpi_specs"), .include_deprivation_matrix = TRUE, .generate_output = FALSE, .formatted_output = TRUE, .mpi_output_filename = NULL, .include_table_summary = TRUE, .include_specs = FALSE )
compute_mpi( .data, .deprivation_profile, ..., .mpi_specs = getOption("mpi_specs"), .include_deprivation_matrix = TRUE, .generate_output = FALSE, .formatted_output = TRUE, .mpi_output_filename = NULL, .include_table_summary = TRUE, .include_specs = FALSE )
.data |
A tidy data frame where each observation is the unit of analysis defined in |
.deprivation_profile |
list of deprivation profile created using |
... |
Grouping columns (supports tidyselect), e.g. area (country, urbanity, region, province), sex, ethnic group, etc. |
.mpi_specs |
MPI specifications defined in |
.include_deprivation_matrix |
Whether to include deprivation matrix in the output. |
.generate_output |
Whether to generate an output (Excel file) as side effect. |
.formatted_output |
NOT YET IMPLEMENTED. Whether formatting is to be applied to the output. |
.mpi_output_filename |
Output filename. |
.include_table_summary |
NOT YET IMPLEMENTED. Whether to include summary information in the generated output. |
.include_specs |
NOT YET IMPLEMENTED. Whether to include MPI specification in the generated output. |
Returns list of objects: index
(the MPI), contribution
(contribution by dimension), headcount_ratio
(censored and uncensored), and deprivation_matrix
(censored and uncensored). If poverty_cutoffs
defined in define_mpi_specs
contain more than one (1) value, index
and contribution
object will output each cutoff in a separate table.
Alkire-Foster Method
How to Apply the Alkire-Foster Method
define_mpi_specs, define_deprivation, save_mpi
# ---------------------------------- # Load MPI specs from the built-in specs file specs_file <- system.file("extdata", "global-mpi-specs.csv", package = "mpindex") mpi_specs <- define_mpi_specs(specs_file, .uid = 'uuid') # ---------------------------------- # Create an empty list to store deprivation profile for each indicator deprivation_profile <- list() deprivation_profile$nutrition <- df_household_roster |> define_deprivation( .indicator = nutrition, .cutoff = undernourished == 1 & age < 70, .collapse = TRUE ) deprivation_profile$child_mortality <- df_household |> define_deprivation( .indicator = child_mortality, .cutoff = with_child_died == 1 ) deprivation_profile$year_schooling <- df_household_roster |> define_deprivation( .indicator = year_schooling, .cutoff = completed_6yrs_schooling == 2, .collapse = TRUE ) deprivation_profile$school_attendance <- df_household_roster |> define_deprivation( .indicator = school_attendance, .cutoff = attending_school == 2 & age %in% c(5:24), .collapse = TRUE ) deprivation_profile$cooking_fuel <- df_household |> define_deprivation( .indicator = cooking_fuel, .cutoff = cooking_fuel %in% c(4:6, 9) ) deprivation_profile$sanitation <- df_household |> define_deprivation( .indicator = sanitation, .cutoff = toilet > 1 ) deprivation_profile$drinking_water <- df_household |> define_deprivation( .indicator = drinking_water, .cutoff = drinking_water == 2 ) deprivation_profile$electricity <- df_household |> define_deprivation( .indicator = electricity, .cutoff = electricity == 2 ) deprivation_profile$housing <- df_household |> define_deprivation( .indicator = housing, .cutoff = roof %in% c(5, 7, 9) | walls %in% c(5, 8, 9, 99) == 2 | floor %in% c(5, 6, 9) ) deprivation_profile$assets <- df_household |> dplyr::mutate_at(dplyr::vars(dplyr::starts_with('asset_')), ~ dplyr::if_else(. > 0, 1L, 0L)) |> dplyr::mutate( asset_phone = dplyr::if_else( (asset_telephone + asset_mobile_phone) > 0, 1L, 0L ) ) |> dplyr::mutate( with_hh_conveniences = ( asset_tv + asset_phone + asset_computer + asset_animal_cart + asset_bicycle + asset_motorcycle + asset_refrigerator) > 1, with_mobility_assets = (asset_car + asset_truck) > 0 ) |> define_deprivation( .indicator = assets, .cutoff = !(with_hh_conveniences & with_mobility_assets) ) # ---------------------------------- # Compute the MPI mpi_result <- df_household |> compute_mpi(deprivation_profile) # ---------------------------------- # You may also save your output into an Excel file ## Not run: save_mpi(mpi_result, .filename = 'MPI Sample Output') ## End(Not run)
# ---------------------------------- # Load MPI specs from the built-in specs file specs_file <- system.file("extdata", "global-mpi-specs.csv", package = "mpindex") mpi_specs <- define_mpi_specs(specs_file, .uid = 'uuid') # ---------------------------------- # Create an empty list to store deprivation profile for each indicator deprivation_profile <- list() deprivation_profile$nutrition <- df_household_roster |> define_deprivation( .indicator = nutrition, .cutoff = undernourished == 1 & age < 70, .collapse = TRUE ) deprivation_profile$child_mortality <- df_household |> define_deprivation( .indicator = child_mortality, .cutoff = with_child_died == 1 ) deprivation_profile$year_schooling <- df_household_roster |> define_deprivation( .indicator = year_schooling, .cutoff = completed_6yrs_schooling == 2, .collapse = TRUE ) deprivation_profile$school_attendance <- df_household_roster |> define_deprivation( .indicator = school_attendance, .cutoff = attending_school == 2 & age %in% c(5:24), .collapse = TRUE ) deprivation_profile$cooking_fuel <- df_household |> define_deprivation( .indicator = cooking_fuel, .cutoff = cooking_fuel %in% c(4:6, 9) ) deprivation_profile$sanitation <- df_household |> define_deprivation( .indicator = sanitation, .cutoff = toilet > 1 ) deprivation_profile$drinking_water <- df_household |> define_deprivation( .indicator = drinking_water, .cutoff = drinking_water == 2 ) deprivation_profile$electricity <- df_household |> define_deprivation( .indicator = electricity, .cutoff = electricity == 2 ) deprivation_profile$housing <- df_household |> define_deprivation( .indicator = housing, .cutoff = roof %in% c(5, 7, 9) | walls %in% c(5, 8, 9, 99) == 2 | floor %in% c(5, 6, 9) ) deprivation_profile$assets <- df_household |> dplyr::mutate_at(dplyr::vars(dplyr::starts_with('asset_')), ~ dplyr::if_else(. > 0, 1L, 0L)) |> dplyr::mutate( asset_phone = dplyr::if_else( (asset_telephone + asset_mobile_phone) > 0, 1L, 0L ) ) |> dplyr::mutate( with_hh_conveniences = ( asset_tv + asset_phone + asset_computer + asset_animal_cart + asset_bicycle + asset_motorcycle + asset_refrigerator) > 1, with_mobility_assets = (asset_car + asset_truck) > 0 ) |> define_deprivation( .indicator = assets, .cutoff = !(with_hh_conveniences & with_mobility_assets) ) # ---------------------------------- # Compute the MPI mpi_result <- df_household |> compute_mpi(deprivation_profile) # ---------------------------------- # You may also save your output into an Excel file ## Not run: save_mpi(mpi_result, .filename = 'MPI Sample Output') ## End(Not run)
A deprivation cutoff must be set for each indicator defined in the MPI specifications. This step establishes the first cutoff in the methodology where every person/household (defined as the unit of analysis) can be identified as deprived or non-deprived with respect to each indicator.
For each indicator, 0
will be used to indicate "not deprived", 1
if deprived, and NA
if missing or non-response. Additional column containing the product of the value of the indicator obtained and its corresponding weight will also be computed for convenience.
define_deprivation( .data, .indicator, .cutoff, .mpi_specs = getOption("mpi_specs"), .collapse = FALSE, .set_na_equal_to = 0, .collapse_condition = NULL )
define_deprivation( .data, .indicator, .cutoff, .mpi_specs = getOption("mpi_specs"), .collapse = FALSE, .set_na_equal_to = 0, .collapse_condition = NULL )
.data |
A data frame or tibble |
.indicator |
Name of indicator defined in MPI specs (must exactly match the specs). |
.cutoff |
A conditional logic that defines the poverty line to determine whether deprived or not. |
.mpi_specs |
MPI specifications defined in |
.collapse |
A boolean indicating whether to collapse the data frame or not. This is useful, for instance, if the original data where the |
.set_na_equal_to |
Coerce value from NA to either |
.collapse_condition |
NOT YET FULLY IMPLEMENTED. ONLY WORKS WITH DEFAULT. A condition when |
A data frame of deprivation value for the indicator (.*_unweighted
): 0
for "not deprived", 1
for deprived, and NA
for missing and non-response; and product of .*_unweighted
and its corresponding weight (.*_weighted
).
How to Apply the Alkire-Foster Method
# Use sample specs file included in the package specs_file <- system.file( "extdata", "global-mpi-specs.csv", package = "mpindex" ) specs <- define_mpi_specs(specs_file, .uid = 'uuid') # Using built-in dataset df_household |> define_deprivation( .indicator = drinking_water, .cutoff = drinking_water == 2 ) df_household_roster |> define_deprivation( .indicator = school_attendance, .cutoff = attending_school == 2, .collapse = TRUE )
# Use sample specs file included in the package specs_file <- system.file( "extdata", "global-mpi-specs.csv", package = "mpindex" ) specs <- define_mpi_specs(specs_file, .uid = 'uuid') # Using built-in dataset df_household |> define_deprivation( .indicator = drinking_water, .cutoff = drinking_water == 2 ) df_household_roster |> define_deprivation( .indicator = school_attendance, .cutoff = attending_school == 2, .collapse = TRUE )
Use to define MPI dimensions, indicators and its corresponding weights using any of the accessible file types: .xlsx
(Excel), .json
, .csv
, or .txt
(TSV). You can also set the poverty cutoff or list of poverty cutoffs (to achieve gradient list of MPIs) that will be used in the computation of MPI.
define_mpi_specs( .mpi_specs_file = NULL, .indicators = NULL, .poverty_cutoffs = 1/3, .unit_of_analysis = NULL, .aggregation = NULL, .uid = NULL, .source_of_data = NULL, .names_separator = ">", .save_as_global_options = TRUE )
define_mpi_specs( .mpi_specs_file = NULL, .indicators = NULL, .poverty_cutoffs = 1/3, .unit_of_analysis = NULL, .aggregation = NULL, .uid = NULL, .source_of_data = NULL, .names_separator = ">", .save_as_global_options = TRUE )
MPI specifications data frame required in compute_mpi function. As as side effect, a global option named ‘mpi_specs' will be saved for efficiency. See 'getOption(’mpi_specs')'.
# Use sample specs file included in the package specs_file <- system.file( "extdata", "global-mpi-specs.csv", package = "mpindex" ) # To see other sample specs file (with different supported file format) system.file("extdata", package = "mpindex") |> list.files()
# Use sample specs file included in the package specs_file <- system.file( "extdata", "global-mpi-specs.csv", package = "mpindex" ) # To see other sample specs file (with different supported file format) system.file("extdata", package = "mpindex") |> list.files()
This is a synthetic dataset containing household information primarily used for demonstration purposes on how to use the mpindex
package.
df_household
df_household
A tibble with 198 rows and 21 variables:
Unique ID
Urbanity: Rural
or Urban
Acess to drinking water: 1
- improved; 2
- unimproved
Service level of toilet or sanitation facility: 1
- basic; 2
- limited; 3
- unimproved; 4
- open defecation
With at least one (1) child died in the last five (5) years: 1
- with child died; 2
- without child died
Main construction material of the roof: 1
- galvanized iron/aluminum; 2
- concrete/clay tile; 3
- half galvanized iron and half concrete; 4
- wood/bamboo; 5
- cogon/nipa/anahaw; 6
- asbestos; 7
- makeshift/salvaged/improvised materials; 9
- other construction material
Main construction material of the outer walls: 1
- concrete/brick/stone; 2
- wood; 3
- half concrete/brick/stone and half wood; 4
- Galvanized iron/aluminum; 5
- bamboo/sawali/cogon/nipa; 6
- asbestos; 7
- glass; 8
- makeshift/salvaged/improvised materials; 9
- none; 10
- concrete hollow blocks; 11
- concrete hollow blocks/wood; 12
- shear walls; 99
- other construction material
Main construction material of the floor: 1
- concrete; 2
- wood; 3
- coconut lumber; 4
- bamboo; 5
- earth/sand/mud; 6
- makeshift/salvaged/improvised materials; 9
- other construction material
Access to electricity: 1
- with access to electricity; 2
- without access to electricity
Fuel use for cooking: 1
- electricity; 2
- kerosene (gaas); 3
- liquified petroleum gas (LPG); 4
- charcoal; 5
- wood; 6
- none; 9
- other cooking fuel such as dung, agricultural crop, or shrubs
Number of working radio owned by the household
Number of working television owned by the household
Number of working telephone owned by the household
Number of working mobile phone owned by the household
Number of working computer owned by the household
Number of animal carts owned by the household
Number of bicycle owned by the household
Number of motorcylce owned by the household
Number of working refrigerator owned by the household
Number of car owned by the household
Number of trucks owned by the household
df_household
df_household
This dataset contains a many-to-one relationship with the df_household dataset. Hence, you can apply joins using the uuid
.
df_household_roster
df_household_roster
A tibble with 905 rows and 8 variables:
Unique ID
Number identifier for each member within the household
Urbanity: Rural
or Urban
Sex of the household member
Age of the household member
Whether the household member (aged 5-24 years old) is currently attending school: 1
- currently attending; 2
- currently not attending
Whether completed at least six (6) years of schooling: 1
- completed; 2
-not completed
Whether the household member (aged below 70 years old) is undernourished: 1
- undernourished; 2
- not undernourished
df_household_roster
df_household_roster
Save the MPI output into an Excel file format.
save_mpi( .mpi_output, .mpi_specs = getOption("mpi_specs"), .filename = NULL, .formatted_output = TRUE, .include_table_summary = TRUE, .include_specs = FALSE )
save_mpi( .mpi_output, .mpi_specs = getOption("mpi_specs"), .filename = NULL, .formatted_output = TRUE, .include_table_summary = TRUE, .include_specs = FALSE )
.mpi_output |
An object derived from compute_mpi. |
.mpi_specs |
MPI specifications defined in |
.filename |
Output filename |
.formatted_output |
Whether formatting is to be applied to the output. |
.include_table_summary |
NOT YET IMPLEMENTED. Whether to include summary information in the generated output. |
.include_specs |
Whether to include MPI specification in the generated output. |
Returns the file location of the output generated.
## Not run: # It requires an MPI output (list type) in the first argument save_mpi(mpi_result, .filename = "MPI Sample Output") ## End(Not run)
## Not run: # It requires an MPI output (list type) in the first argument save_mpi(mpi_result, .filename = "MPI Sample Output") ## End(Not run)
Use built-in specification file for Global MPI.
use_global_mpi_specs(...)
use_global_mpi_specs(...)
... |
Accepts all arguments in |
Global MPI specs
use_global_mpi_specs()
use_global_mpi_specs()