-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5222729
commit 8c8d8d5
Showing
38 changed files
with
4,843 additions
and
5,134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
Package: mpindex | ||
Type: Package | ||
Title: Multidimensional Poverty Index (MPI) | ||
Version: 0.2.0 | ||
Version: 0.2.1 | ||
Authors@R: c( | ||
person( | ||
"Bhas", | ||
"Abdulsamad", | ||
email = "aeabdulsamad@gmail.com", | ||
email = "aeabdulsamad@gmail.com", | ||
comment = c(ORCID = "0009-0002-5891-8124"), | ||
role = c("aut", "cre", "cph") | ||
) | ||
) | ||
Author: Bhas Abdulsamad [aut, cre, cph] | ||
(<https://orcid.org/0009-0002-5891-8124>) | ||
Maintainer: Bhas Abdulsamad <aeabdulsamad@gmail.com> | ||
Description: A set of easy-to-use functions for computing the Multidimensional Poverty Index (MPI). | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Suggests: rlang, dplyr, tidyr, tibble, stringr, jsonlite, openxlsx, | ||
testthat (>= 3.0.0), knitr, purrr, rmarkdown, gt | ||
Imports: dplyr, tidyr, stringr, jsonlite, purrr, tibble, openxlsx | ||
Suggests: rlang, testthat (>= 3.0.0), lifecycle, knitr, rmarkdown, gt | ||
Config/testthat/edition: 3 | ||
RoxygenNote: 7.2.3 | ||
BugReports: https://github.com/yng-me/mpindex/issues | ||
URL: https://github.com/yng-me/mpindex | ||
URL: https://github.com/yng-me/mpindex, | ||
https://yng-me.github.io/mpindex/ | ||
VignetteBuilder: knitr | ||
Depends: R (>= 2.10) | ||
NeedsCompilation: no | ||
Packaged: 2023-09-12 03:33:31 UTC; bhasabdulsamad | ||
Packaged: 2024-01-09 09:34:51 UTC; bhasabdulsamad | ||
Repository: CRAN | ||
Date/Publication: 2023-09-12 08:50:08 UTC | ||
Date/Publication: 2024-01-09 09:50:02 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
YEAR: 2023 | ||
COPYRIGHT HOLDER: mpindex authors | ||
COPYRIGHT HOLDER: mpindex authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,47 @@ | ||
b617e0fc2754f51c29b60db9f5510eb8 *DESCRIPTION | ||
1e2ebd2b67634e1b81f4acdc2b5559e0 *LICENSE | ||
8e7baca9a7a7228e359d62df3278ec13 *NAMESPACE | ||
7cd27c0925d5533f03cabb3d949f8af8 *R/compute-contribution.R | ||
309c084f57a5b8703cb98f61b0c906f6 *R/compute-headcount-ratio-adj.R | ||
ae8600736d39ed2dc4ce1a7b2d3bfd86 *R/compute-headcount-ratio.R | ||
a53ca0a3466922677a8ee07bca2b2865 *R/compute-mpi.R | ||
bcd7b10a4fe33a549d7e31f3698bc41e *R/create-deprivation-matrix.R | ||
f6e713d1ddfe99806fe6f71f9006b60f *DESCRIPTION | ||
1ec190c4bb964fc83ebb726ce769b2a1 *LICENSE | ||
2c7cde337a5b4bd39e256cd60bb9fd3c *NAMESPACE | ||
37350601b8296202980b3a08c51bb915 *NEWS.md | ||
32e288b56dc5d9326fd5675a74346213 *R/compute-contribution.R | ||
0ee295eb50ee588d3703d6d7d7beac4d *R/compute-headcount-ratio-adjusted.R | ||
8cbde169e2304d8fc7bcda7d290888c0 *R/compute-headcount-ratio.R | ||
256ba6da7d5bdb73722a6efe3599e2ee *R/compute-mpi.R | ||
9d12aaa87e794ad8751bfe981e32e7f4 *R/create-deprivation-matrix.R | ||
ece6e86aa84f51890077ccea4f2e7c29 *R/data-df_household.R | ||
98d0b3d8525ef2405f2b30dddf666b0b *R/data-df_household_roster.R | ||
0023c80aa804f8f49995f1fca6aa2193 *R/define-deprivation.R | ||
68a4845620a0d345242a9e54998577df *R/define-mpi-specs.R | ||
90a796f07d79b1ab35e76b7bb7f17cea *R/helpers.R | ||
a6c7b7713d15ab991eb1343cd8ac0d5a *R/save_mpi.R | ||
a7e5abba8a0001f2f40b84650903999e *R/utils.R | ||
e90e33c18b2f4a9631eed401ba66df82 *R/write-as-excel.R | ||
88e51b6ec38bde33053562050fa6f0e9 *README.md | ||
2988b06502617ee398be3369a461267f *build/vignette.rds | ||
ca3a85b56b1542930a0461ab33a998bb *R/define-deprivation.R | ||
df247fc311e9715f6bf3f566419986eb *R/define-mpi-specs.R | ||
d05e54a9ca0104354ac883246df5160a *R/helpers.R | ||
e8267b47ec2e66747314d70f56e77333 *R/save_mpi.R | ||
77e9c802aa5f695e394b0d647de60e46 *R/utils.R | ||
34da6f1891d551eeca8b1346e4e3c68a *R/write-as-excel.R | ||
ec73b29285f01919e71dbc18c7838052 *README.md | ||
7e473e0e4dd549e784980a5ad3a0a708 *build/vignette.rds | ||
40b7eeeff3ada6accbc801b5f888ca0c *data/df_household.rda | ||
85b8b0d72003e9ed871d853c521a6d46 *data/df_household_roster.rda | ||
dc5c8922e444976390b2429a81154667 *inst/doc/mpindex.R | ||
04dfbee6f24cb7092675f9d658b33c56 *inst/doc/mpindex.Rmd | ||
31eadbd8780466368faef0b097a497b2 *inst/doc/mpindex.html | ||
0d0246ddc536d18851f49b68f19609c7 *inst/doc/mpindex.R | ||
e99e1eb8bf104007eef84996e6e52fbb *inst/doc/mpindex.Rmd | ||
473f5180151d0f07d6407a0c600db320 *inst/doc/mpindex.html | ||
723e4f44bff1404bc7190888673e7109 *inst/extdata/global-mpi-specs.csv | ||
c50a8e6d72c85bfe6993201cf6818f07 *inst/extdata/global-mpi-specs.json | ||
18d9916e6079f2d1a788407bcfb01875 *inst/extdata/global-mpi-specs.txt | ||
7181ff6ca18599828b38b9adfd3efa98 *inst/extdata/global-mpi-specs.xlsx | ||
fa6c6ce4cce43a4c2d3bc43650049fb3 *man/compute_mpi.Rd | ||
7ba386f0bab8963a5574460f7d1900c8 *man/define_deprivation.Rd | ||
0df9adcff5d5d9397f7730513225f8a5 *man/define_mpi_specs.Rd | ||
743507261bd16389efe336dea6d562c7 *man/compute_mpi.Rd | ||
9a7eab8a0e02ad274bae1c26db593a44 *man/define_deprivation.Rd | ||
c4fe8d6d19ff8570eedbb864b2438865 *man/define_mpi_specs.Rd | ||
8e53f31aa28a846e9a2201bf8c8bb435 *man/df_household.Rd | ||
a1aefda3e77ecc166958d225081d079c *man/df_household_roster.Rd | ||
225ffc30fd7efc6af6fa0a35fb5c5c05 *man/save_mpi.Rd | ||
52809d6e24fd31dabceaa335ae485dd2 *tests/deprivation_profile.R | ||
a1b8c987c676c16af790f563f96cbb1f *man/figures/lifecycle-deprecated.svg | ||
524333b189041801c9b9de4d895ecb5a *man/save_mpi.Rd | ||
f3120a0292a66e45dcbee40c9954c6e0 *man/use_global_mpi_specs.Rd | ||
0ca1af71d8624fc290dff97879bd6083 *tests/deprivation-profile-simple.R | ||
910ec2c6e0a3d4efed8a6e4ea7cc6080 *tests/deprivation-profile.R | ||
e76c67aceb5cb3960e3f94fac849f324 *tests/testthat.R | ||
52acbd309a5d49a3c650e294862d44cd *tests/testthat/test-compute-contribution.R | ||
4cbe9d2d12159de427a4fbb2a0a36ae3 *tests/testthat/test-compute-headcount-ratio-adj.R | ||
cfd0008ee61ad1a11e3db3a344429380 *tests/testthat/test-compute-headcount-ratio.R | ||
a59380f9423cec41ad7ae3a8b1bf83eb *tests/testthat/test-compute-mpi.R | ||
0c0de155ac3d12b35ea562628f229542 *tests/testthat/test-create-deprivation-matrix.R | ||
6e13c799add12a54e5c8bb3f9203be32 *tests/testthat/test-define-deprivation.R | ||
237a50b33b4679ac264dc8eddffb5115 *tests/testthat/test-define-mpi-specs.R | ||
04dfbee6f24cb7092675f9d658b33c56 *vignettes/mpindex.Rmd | ||
59c6481c12fbdc7ad57ae73dae989fc1 *tests/testthat/test-compute-contribution.R | ||
5c955db746a1d62f61922b05721c6e00 *tests/testthat/test-compute-headcount-ratio-adjusted.R | ||
5eae2a642d535a93581d4116d654bf11 *tests/testthat/test-compute-headcount-ratio.R | ||
2bef07b6b665b40f940b562d08042479 *tests/testthat/test-compute-mpi.R | ||
e9583ea7a37ea316fbdde7840430d09b *tests/testthat/test-create-deprivation-matrix.R | ||
f707cd4ade224f47572bdd3078a8c6cb *tests/testthat/test-define-deprivation.R | ||
779f3f657d0f7edcbeee81d25cf4ca51 *tests/testthat/test-define-mpi-specs.R | ||
e99e1eb8bf104007eef84996e6e52fbb *vignettes/mpindex.Rmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# mpindex 0.2.1 | ||
|
||
* Changed returned value of `define_mpi_specs` from list to data frame with a class of `mpi_specs_df`. By default, it stores a global option named `mpi_specs` which can be accessed using `getOption('mpi_specs')`. Other specifications are now stored as `attributes`. | ||
* Changed default value of `.unit_of_analysis` from `households` to `NULL`. | ||
* `save_mpi` now allows unformatted output (tidy format) when generating an output. | ||
* Implemented feature to include MPI specification in the output by setting `.include_specs` tot `TRUE` in `save_mpi`. | ||
* Deprecated `.names_separator` argument in `define_mpi_specs`. | ||
* Enhancement of `define_deprivation` based on #17. | ||
* Added `use_global_mpi_specs()` wrapper function to use Global MPI specification. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
compute_contribution <- function( | ||
.data, | ||
..., | ||
.mpi_specs = getOption('mpi_specs') | ||
.mpi_specs = getOption("mpi_specs") | ||
|
||
) { | ||
|
||
validate_mpi_specs(.mpi_specs) | ||
|
||
n <- NULL | ||
MPI <- NULL | ||
mpi <- NULL | ||
`:=` <- NULL | ||
spec_attr <- attributes(.mpi_specs) | ||
|
||
.df_contrib <- .data |> dplyr::select(dplyr::any_of(.mpi_specs$aggregation), n, ...) | ||
df <- .data |> | ||
dplyr::select(dplyr::any_of(spec_attr$aggregation), n, ...) | ||
|
||
.w <- .mpi_specs$indicators$weight | ||
.ind <- .mpi_specs$indicators$variable_name | ||
w <- .mpi_specs$weight | ||
indicator <- .mpi_specs$variable_name | ||
|
||
for(i in seq_along(.ind)) { | ||
|
||
.contrib <- .data |> | ||
dplyr::select(MPI, !!as.name(.ind[i])) |> | ||
for (i in seq_along(indicator)) { | ||
contrib <- .data |> | ||
dplyr::select(mpi, !!as.name(indicator[i])) |> | ||
dplyr::transmute( | ||
!!as.name(.ind[i]) := dplyr::if_else( | ||
MPI == 0, | ||
!!as.name(indicator[i]) := dplyr::if_else( | ||
mpi == 0, | ||
0, | ||
(100 * (.w[i] * !!as.name(.ind[i]))) / MPI | ||
(100 * (w[i] * !!as.name(indicator[i]))) / mpi | ||
) | ||
) | ||
|
||
.df_contrib <- .df_contrib |> | ||
dplyr::bind_cols(.contrib) | ||
df <- df |> | ||
dplyr::bind_cols(contrib) | ||
} | ||
|
||
return(.df_contrib |> rename_indicators(.mpi_specs = .mpi_specs)) | ||
class(df) <- c("mpi_contribution", class(df)) | ||
|
||
return(df |> rename_indicators(.mpi_specs = .mpi_specs)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
compute_headcount_ratio_adjusted <- function(.data, .aggregation = NULL, ...) { | ||
n <- NULL | ||
mpi <- NULL | ||
headcount_ratio <- NULL | ||
intensity <- NULL | ||
is_deprived <- NULL | ||
deprivation_score <- NULL | ||
|
||
df <- .data |> | ||
dplyr::group_by(...) | ||
|
||
if (!is.null(.aggregation)) { | ||
if (.aggregation %in% names(.data)) { | ||
df <- .data |> | ||
dplyr::group_by(!!as.name(.aggregation), ...) | ||
} | ||
} | ||
|
||
df <- df |> | ||
dplyr::summarise( | ||
n = dplyr::n(), | ||
headcount_ratio = (sum(is_deprived, na.rm = T)) / n, | ||
intensity = dplyr::if_else( | ||
sum(is_deprived, na.rm = T) == 0, 0, | ||
sum(deprivation_score, na.rm = T) * (1 / sum(is_deprived, na.rm = T)) | ||
), | ||
mpi = headcount_ratio * intensity, # OR, MPI = (1 / n) * sum(censored_score, na.rm = T), | ||
.groups = "drop" | ||
) | ||
|
||
|
||
attr(df$headcount_ratio, "label") <- "Headcount Ratio (H)" | ||
attr(df$intensity, "label") <- "Intensity of Deprivation Among the Poor (A)" | ||
attr(df$mpi, "label") <- "MPI (H x A)" | ||
|
||
class(df) <- c("mpi_df", class(df)) | ||
|
||
return(df) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
compute_headcount_ratio <- function(.data, .aggregation = NULL, ...) { | ||
|
||
n <- NULL | ||
.pattern_str <- '^d\\d{2}_i\\d{2}.*' | ||
pattern_str <- "^d\\d{2}_i\\d{2}.*" | ||
|
||
df <- .data |> | ||
dplyr::group_by(...) |> | ||
dplyr::add_count() |> | ||
dplyr::ungroup() |> | ||
dplyr::group_by(n, ...) |> | ||
dplyr::summarise_at(dplyr::vars(dplyr::matches(.pattern_str)), mean, na.rm = T) |> | ||
dplyr::select(n, ..., dplyr::matches(.pattern_str)) | ||
dplyr::summarise_at( | ||
dplyr::vars(dplyr::matches(pattern_str)), | ||
mean, | ||
na.rm = TRUE | ||
) |> | ||
dplyr::select(n, ..., dplyr::matches(pattern_str)) | ||
|
||
|
||
if(!is.null(.aggregation)) { | ||
if(.aggregation %in% names(.data)) { | ||
if (!is.null(.aggregation)) { | ||
if (.aggregation %in% names(.data)) { | ||
df <- .data |> | ||
dplyr::group_by(!!as.name(.aggregation), ...) |> | ||
dplyr::add_count() |> | ||
dplyr::group_by(!!as.name(.aggregation), n, ...) |> | ||
dplyr::summarise_at(dplyr::vars(dplyr::matches(.pattern_str)), mean, na.rm = T) |> | ||
dplyr::select(!!as.name(.aggregation), n, ..., dplyr::matches(.pattern_str)) | ||
dplyr::summarise_at( | ||
dplyr::vars(dplyr::matches(pattern_str)), | ||
mean, | ||
na.rm = TRUE | ||
) |> | ||
dplyr::select( | ||
!!as.name(.aggregation), n, | ||
..., | ||
dplyr::matches(pattern_str) | ||
) |> | ||
dplyr::ungroup() | ||
} | ||
} | ||
|
||
return(df) | ||
class(df) <- c("mpi_headcount_ratio", class(df)) | ||
|
||
return(df) | ||
} |
Oops, something went wrong.