This document presents an illustration of a simple application of
mpindex
package for computing the Multidimensional Poverty
Index (MPI) using the Alkire-Foster (AF) counting method developed by
Sabina Alkire and James Foster.
To install the mpindex
package from CRAN:
install.packages('mpindex')
If you want to get the latest development version of
mpindex
, install it from GitHub. Note that you may need to
install first devtools
.
::install_github('yng-me/mpindex') devtools
Load the package once you have successfully completed the installation.
library(mpindex)
The initial step is to prepare an MPI specification file which will serve as references in the computation as well as generation of output in the later part of the process. This file should contain information about MPI dimensions, indicators and their corresponding weights.
This file should also be easy to create using the most common and
accessible file types such as .xlsx
(Excel),
.json
, .csv
, or .txt
(TSV).
For convenience, mpindex
has included built-in
specification files (in different formats). Each file contains
dimensions, indicators, weight, and other relevant information of the
Global MPI.
To see the list of files available:
system.file("extdata", package = "mpindex") |> list.files()
#> [1] "global-mpi-specs.csv" "global-mpi-specs.json" "global-mpi-specs.txt"
#> [4] "global-mpi-specs.xlsx"
To use a built-in specification file, say the .csv
file,
use below script to first get the full path of the file.
<- system.file("extdata", "global-mpi-specs.csv", package = "mpindex") specs_file
Global MPI – Dimensions, Indicators, Deprivation Cutoffs, and Weights | ||||
Dimension | Indicator | Variable | Weight | Description |
---|---|---|---|---|
Health | Nutrition | nutrition | 0.16666667 | Any person under 70 years of age for whom there is nutritional information is undernourished. |
Health | Child mortality | child_mortality | 0.16666667 | A child under 18 has died in the household in the five-year period preceding the survey. |
Education | Years of schooling | year_schooling | 0.16666667 | No eligible household member has completed six years of schooling. |
Education | School attendance | school_attendance | 0.16666667 | Any school-aged child is not attending school up to the age at which he/she would complete class 8. |
Living Standards | Cooking fuel | cooking_fuel | 0.05555556 | A household cooks using solid fuel, such as dung, agricultural crop, shrubs, wood, charcoal, or coal. |
Living Standards | Sanitation | sanitation | 0.05555556 | The household has unimproved or no sanitation facility or it is improved but shared with other households. |
Living Standards | Drinking water | drinking_water | 0.05555556 | The household's source of drinking water is not safe or safe drinking water is a 30-minute or longer walk from home, roundtrip. |
Living Standards | Electricity | electricity | 0.05555556 | The household has no electricity. |
Living Standards | Housing | housing | 0.05555556 | The household has inadequate housing materials in any of the three components: floor, roof, or walls. |
Living Standards | Assets | assets | 0.05555556 | The household does not own more than one of these assets: radio, TV, telephone, computer, animal cart, bicycle, motorbike, or refrigerator, and does not own a car or truck. |
Source: Alkire, S., Kanagaratnam, U. and Suppa, N. (2020). ‘The global Multidimensional Poverty Index (MPI): 2020 revision’, OPHI MPI Methodological Note 49, Oxford Poverty and Human Development Initiative, University of Oxford. |
You can also define and create your own specification file if you prefer to or if you happen to use different sets of dimensions and indicators. At the minimum, however, this file should contain the following columns/variables:
Dimension
,Indicator
,Variable
,Weight
,Description
(optional).Note that the order in which you put these columns does not matter and also the names are not case sensitive, but make sure to spell the column names correctly.
You may download the template here if you do not want to start from scratch: MPI specification file sample.
define_mpi_specs
Once you have prepared the specification file, load it using the
define_mpi_specs
function (type
?define_mpi_specs
for a help text).
For demonstration purposes, we will use the built-in specification file, discussed above.
<- system.file("extdata", "global-mpi-specs.csv", package = "mpindex")
specs_file <- define_mpi_specs(specs_file) mpi_specs
define_mpi_specs
requires a specification file as its
first argument. The default poverty cutoff is set to 1/3
(based on Global MPI), with a unit of analysis set to
households
. You can also define a list of poverty cutoffs
by specifying in the .poverty_cutoffs
argument to achieve
gradient MPIs.
<- define_mpi_specs(
mpi_specs .mpi_specs_file = specs_file,
.poverty_cutoffs = c(1/3, 0.2, 0.8)
)
If your dataset contains unique ID, like uuid
, it is
recommended to define it here using the .uid
argument.
<- define_mpi_specs(
mpi_specs .mpi_specs_file = specs_file,
.uid = 'uuid'
)
You can also set the aggregation level. Make sure it corresponds to
the column name present in your dataset (see ?df_househod
and more below).
<- define_mpi_specs(
mpi_specs .mpi_specs_file = specs_file,
.poverty_cutoffs = c(1/3, 0.2, 0.8),
.uid = 'uuid',
.aggregation = 'class'
)
.unit_of_analysis
, .source_of_data
, and
.names_separator
are merely used for auto labels when
generating the output later.
It is also recommended to make the MPI specification available
globally, rather than providing the argument manually everytime you use
other functions within the mpindex
(more of this
later).
options(mpi_specs = mpi_specs)
Note: the name to be passed to options
must exactly be
mpi_specs
.
The user of mpindex
is assumed to have basic familiarity
with the concept of tidy data as well as able to perform data wrangling
and transformation using the tidyverse
ecosystem. Under the
hood, mpindex
uses dplyr
verbs to perform data
manipulation.
We also assume that your dataset is already tidy and ready for analysis. See R for Data Science by Hadley Wickham and Garrett Grolemund if you need a refresher.
For this demonstration, we will use two (2) synthetic datasets available within the package:
df_household
household-level data (type
?df_household
for more info)df_household_roster
individual-level data (type
?df_household_roster
for more info)library(dplyr)
glimpse(df_household)
#> Rows: 198
#> Columns: 21
#> $ uuid <chr> "5dbec60a-ebda-47bd-ae18-3b017a221125", "8b70c208-8…
#> $ class <chr> "Rural", "Rural", "Rural", "Rural", "Rural", "Rural…
#> $ drinking_water <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ toilet <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 4, 1, 1, 1, …
#> $ with_child_died <int> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, …
#> $ roof <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ walls <int> 1, 1, 3, 3, 3, 5, 5, 1, 3, 1, 1, 4, 8, 2, 2, 10, 2,…
#> $ floor <int> 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 5, 2, 4, 1, 2, …
#> $ electricity <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, …
#> $ cooking_fuel <int> 3, 5, 5, 5, 5, 5, 5, 3, 3, 1, 3, 5, 5, 5, 5, 5, 5, …
#> $ asset_refrigerator <int> 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, …
#> $ asset_radio <int> 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, …
#> $ asset_tv <int> 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, …
#> $ asset_telephone <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ asset_mobile_phone <int> 4, 3, 2, 2, 5, 2, 1, 6, 2, 4, 1, 2, 3, 0, 0, 2, 0, …
#> $ asset_animal_cart <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ asset_computer <int> 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ asset_motorcycle <int> 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, …
#> $ asset_bicycle <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, …
#> $ asset_car <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ asset_truck <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
glimpse(df_household_roster)
#> Rows: 905
#> Columns: 8
#> $ uuid <chr> "5dbec60a-ebda-47bd-ae18-3b017a221125", "5dbe…
#> $ line_number <int> 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 1, 2, 3, 4, 1, …
#> $ class <chr> "Rural", "Rural", "Rural", "Rural", "Rural", …
#> $ sex <chr> "Male", "Female", "Female", "Male", "Female",…
#> $ age <int> 55, 48, 17, 10, 30, 26, 3, 19, 66, 62, 34, 34…
#> $ attending_school <int> NA, NA, 1, 1, NA, NA, NA, 1, NA, NA, NA, NA, …
#> $ undernourished <int> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, …
#> $ completed_6yrs_schooling <int> 1, 1, 1, 2, 1, 1, NA, 2, 1, 1, 2, 1, 2, NA, 2…
define_deprivation
First, we need to create an empty list, and name it
deprivation_profile
(but feel free to name it whatever you
like).
<- list() deprivation_profile
To create a deprivation profile for each indicator, we use the
define_deprivation
function (see
?define_deprivation
) and add to the
deprivation_profile
list we created above. Make sure that
the deprivation profile for each indicator matches the variable name
declared in the specification file.
For this indicator, we use the df_household_roster
dataset. By default, define_deprivation
sets the
.collapse = FALSE
. Since we need to collapse it to the
household level, we need to set .collapse = TRUE
.
$nutrition <- df_household_roster |>
deprivation_profiledefine_deprivation(
.indicator = nutrition,
.cutoff = undernourished == 1 & age < 70,
.collapse = TRUE
)
For child mortality, we use the df_household
dataset.
But unlike in nutrition
, we do not need to provide the
.collapse
argument since it is not applicable here.
$child_mortality <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = child_mortality,
.cutoff = with_child_died == 1
)
$year_schooling <- df_household_roster |>
deprivation_profiledefine_deprivation(
.indicator = year_schooling,
.cutoff = completed_6yrs_schooling == 2,
.collapse = TRUE
)
$school_attendance <- df_household_roster |>
deprivation_profiledefine_deprivation(
.indicator = school_attendance,
.cutoff = attending_school == 2 & age %in% c(5:24),
.collapse = TRUE
)
$cooking_fuel <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = cooking_fuel,
.cutoff = cooking_fuel %in% c(4:6, 9)
)
$sanitation <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = sanitation,
.cutoff = toilet > 1
)
$drinking_water <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = drinking_water,
.cutoff = drinking_water == 2
)
$electricity <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = electricity,
.cutoff = electricity == 2
)
$housing <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = housing,
.cutoff = roof %in% c(5, 7, 9) | walls %in% c(5, 8, 9, 99) == 2 | floor %in% c(5, 6, 9)
)
For this indicator, we need additional transformation.
$assets <- df_household |>
deprivation_profilemutate_at(vars(starts_with('asset_')), ~ if_else(. > 0, 1L, 0L)) |>
mutate(
asset_phone = if_else(
+ asset_mobile_phone) > 0,
(asset_telephone
1L,
0L
)|>
) mutate(
with_hh_conveniences = (
+ asset_phone + asset_computer +
asset_tv + asset_bicycle +
asset_animal_cart + asset_refrigerator) > 1,
asset_motorcycle with_mobility_assets = (asset_car + asset_truck) > 0
|>
) define_deprivation(
.indicator = assets,
.cutoff = !(with_hh_conveniences & with_mobility_assets)
)
compute_mpi
After completing the deprivation profile, use the
compute_mpi
function and pass the
deprivation_profile
list you created above.
<- df_household |>
mpi_result compute_mpi(deprivation_profile)
names(mpi_result)
#> [1] "index" "contribution" "headcount_ratio"
#> [4] "deprivation_matrix"
$index mpi_result
MPI Results using 33% Poverty Cutoff | |||
Number of households | Headcount Ratio (H) | Intensity of Deprivation Among the Poor (A) | MPI (H x A) |
---|---|---|---|
198 | 0.379 | 0.473 | 0.179 |
$contribution mpi_result
Contribution by Dimenstion and Indicator to MPI using 33% Poverty Cutoff | ||||||||||
Number of households | Health | Education | Living Standards | |||||||
---|---|---|---|---|---|---|---|---|---|---|
Nutrition | Child mortality | Years of schooling | School attendance | Cooking fuel | Sanitation | Drinking water | Electricity | Housing | Assets | |
198 | 21.2 | 1.4 | 33.9 | 20.2 | 6.1 | 1.7 | 0.6 | 1.4 | 2.7 | 10.8 |
$headcount_ratio$uncensored mpi_result
Uncensored Headcount Ratio | ||||||||||
Number of households | Health | Education | Living Standards | |||||||
---|---|---|---|---|---|---|---|---|---|---|
Nutrition | Child mortality | Years of schooling | School attendance | Cooking fuel | Sanitation | Drinking water | Electricity | Housing | Assets | |
198 | 0.237 | 0.015 | 0.813 | 0.258 | 0.293 | 0.091 | 0.020 | 0.051 | 0.086 | 0.763 |
$headcount_ratio$censored mpi_result
Censored Headcount Ratio using 33% Poverty Cutoff | ||||||||||
Number of households | Health | Education | Living Standards | |||||||
---|---|---|---|---|---|---|---|---|---|---|
Nutrition | Child mortality | Years of schooling | School attendance | Cooking fuel | Sanitation | Drinking water | Electricity | Housing | Assets | |
198 | 0.227 | 0.015 | 0.364 | 0.217 | 0.197 | 0.056 | 0.020 | 0.045 | 0.086 | 0.348 |
$deprivation_matrix$uncensored |> head() mpi_result
Uncensored Deprivation Matrix | |||||||||||
uuid | Health | Education | Living Standards | Assets | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Deprivation score | Nutrition | Child mortality | Years of schooling | School attendance | Cooking fuel | Sanitation | Drinking water | Electricity | Housing | ||
5dbec60a-ebda-47bd-ae18-3b017a221125 | 0.222 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
8b70c208-8642-408c-8a51-30bcaa106069 | 0.278 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
aa7cb64d-ba16-4842-8994-8772060f432d | 0.111 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
df3e5c9b-7218-451d-9917-cd552cf4f40f | 0.278 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
57babe6a-c163-4d8e-aa80-3a9bc9290d2d | 0.278 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
ba3f75cd-102d-482d-a979-b9098e9e0e18 | 0.278 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
$deprivation_matrix$censored |> head() mpi_result
Censored Deprivation Matrix using 33% Poverty Cutoff | |||||||||||
uuid | Health | Education | Living Standards | Assets | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Deprivation score | Nutrition | Child mortality | Years of schooling | School attendance | Cooking fuel | Sanitation | Drinking water | Electricity | Housing | ||
5dbec60a-ebda-47bd-ae18-3b017a221125 | 0.000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
8b70c208-8642-408c-8a51-30bcaa106069 | 0.000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
aa7cb64d-ba16-4842-8994-8772060f432d | 0.000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
df3e5c9b-7218-451d-9917-cd552cf4f40f | 0.000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
57babe6a-c163-4d8e-aa80-3a9bc9290d2d | 0.000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
ba3f75cd-102d-482d-a979-b9098e9e0e18 | 0.000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
You may also save your output into an Excel file.
save_mpi(mpi_result, .filename = 'MPI Sample Output')
# ----------------------------------
# Load MPI specs from the built-in specs file
<- system.file("extdata", "global-mpi-specs.csv", package = "mpindex")
specs_file <- define_mpi_specs(specs_file, .uid = 'uuid')
mpi_specs options(mpi_specs = mpi_specs)
# ----------------------------------
# Create an empty list to store deprivation profile for each indicator
<- list()
deprivation_profile
$nutrition <- df_household_roster |>
deprivation_profiledefine_deprivation(
.indicator = nutrition,
.cutoff = undernourished == 1 & age < 70,
.collapse = TRUE
)
$child_mortality <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = child_mortality,
.cutoff = with_child_died == 1
)
$year_schooling <- df_household_roster |>
deprivation_profiledefine_deprivation(
.indicator = year_schooling,
.cutoff = completed_6yrs_schooling == 2,
.collapse = TRUE
)
$school_attendance <- df_household_roster |>
deprivation_profiledefine_deprivation(
.indicator = school_attendance,
.cutoff = attending_school == 2 & age %in% c(5:24),
.collapse = TRUE
)
$cooking_fuel <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = cooking_fuel,
.cutoff = cooking_fuel %in% c(4:6, 9)
)
$sanitation <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = sanitation,
.cutoff = toilet > 1
)
$drinking_water <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = drinking_water,
.cutoff = drinking_water == 2
)
$electricity <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = electricity,
.cutoff = electricity == 2
)
$housing <- df_household |>
deprivation_profiledefine_deprivation(
.indicator = housing,
.cutoff = roof %in% c(5, 7, 9) |
%in% c(5, 8, 9, 99) == 2 |
walls %in% c(5, 6, 9)
floor
)
$assets <- df_household |>
deprivation_profile::mutate_at(
dplyr::vars(dplyr::starts_with('asset_')),
dplyr~ dplyr::if_else(. > 0, 1L, 0L)
|>
) ::mutate(
dplyrasset_phone = dplyr::if_else(
+ asset_mobile_phone) > 0,
(asset_telephone
1L,
0L
)|>
) ::mutate(
dplyrwith_hh_conveniences = (
+ asset_phone + asset_computer +
asset_tv + asset_bicycle +
asset_animal_cart + asset_refrigerator) > 1,
asset_motorcycle with_mobility_assets = (asset_car + asset_truck) > 0
|>
) define_deprivation(
.indicator = assets,
.cutoff = !(with_hh_conveniences & with_mobility_assets)
)
# ----------------------------------
# Compute the MPI
<- df_household |>
mpi_result compute_mpi(deprivation_profile)
# ----------------------------------
# You may also save your output into an Excel file
save_mpi(mpi_result, .filename = 'MPI Sample Output')