Skip to content

Commit

Permalink
Merge pull request #249 from PIP-Technical-Team/QA
Browse files Browse the repository at this point in the history
Merge QA
  • Loading branch information
tonyfujs authored Mar 26, 2024
2 parents 0e5bde0 + 8af3370 commit d16d6a2
Show file tree
Hide file tree
Showing 69 changed files with 2,665 additions and 366 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Meta/
tests/testdata/local/
TEMP/
docs
/sessionInfoLog
14 changes: 9 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: wbpip
Title: What the Package Does (One Line, Title Case)
Version: 0.1.0.9001
Version: 0.1.2
Authors@R:
c(person(given = "Tony",
family = "Fujs",
Expand All @@ -10,13 +10,17 @@ Authors@R:
family = "Eilertsen",
role = "aut",
email = "[email protected]"),
person(given = "R. Andrés",
person(given = "R.Andrés",
family = "Castañeda",
role = "aut",
email = "[email protected]"),
person(given = "Zander",
family = "Prinsloo",
role = "aut",
email = "[email protected]"),
person(given = "Ifeanyi",
family = "Nzegwu Edochie",
role = "aut",
role = "ctb",
email = "[email protected]"),
person(given = "Minh",
family = "Cong Nguyen",
Expand All @@ -30,7 +34,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
testthat,
knitr,
Expand All @@ -48,7 +52,7 @@ Imports:
data.table,
assertthat,
cli,
collapse,
collapse (>= 2.0.9),
MASS
VignetteBuilder: knitr
ByteCompile: true
Expand Down
48 changes: 48 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
# Generated by roxygen2: do not edit by hand

export(check_curve_validity_lb)
export(check_curve_validity_lq)
export(compute_pip_stats)
export(create_functional_form_lb)
export(create_functional_form_lq)
export(deflate_welfare_mean)
export(derive_lb)
export(derive_lq)
export(fill_gaps)
export(gd_clean_data)
export(gd_compute_fit_lb)
export(gd_compute_fit_lq)
export(gd_compute_gini_lb)
export(gd_compute_gini_lq)
export(gd_compute_headcount_lb)
export(gd_compute_headcount_lq)
export(gd_compute_mld_lb)
export(gd_compute_mld_lq)
export(gd_compute_pov_gap_lb)
export(gd_compute_pov_gap_lq)
export(gd_compute_pov_severity_lb)
export(gd_compute_pov_severity_lq)
export(gd_compute_watts_lb)
export(gd_compute_watts_lq)
export(gd_estimate_distribution)
export(gd_lq_key_values)
export(get_9010_ratio)
export(get_average_shortfall)
export(get_bins)
Expand All @@ -13,5 +35,31 @@ export(get_lorenz)
export(get_number_poor)
export(get_palma_ratio)
export(get_total_shortfall)
export(md_compute_fgt)
export(md_compute_gini)
export(md_compute_headcount)
export(md_compute_mld)
export(md_compute_polarization)
export(md_compute_pov_gap)
export(md_compute_pov_severity)
export(md_compute_poverty_stats)
export(md_compute_watts)
export(md_quantile_values)
export(md_quantile_welfare_share)
export(md_welfare_share_at)
export(predict_request_year_mean)
export(regres)
export(use_lq_for_distributional)
export(use_lq_for_poverty)
export(value_at_lb)
export(value_at_lq)
import(collapse, except = fdroplevels)
import(data.table)
import(data.table, except = fdroplevels)
importFrom(cli,cli_abort)
importFrom(cli,cli_alert)
importFrom(cli,cli_alert_danger)
importFrom(cli,cli_alert_info)
importFrom(cli,cli_alert_success)
importFrom(cli,cli_inform)
importFrom(cli,cli_warn)
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# wbpip (development version)
# wbpip 0.1.2

# wbpip 0.1.1

* Add new functions to compute the following indicators:
- Number of poor
Expand Down
2 changes: 1 addition & 1 deletion R/gd_clean_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @param quiet logical: If TRUE output messages are suppressed.
#'
#' @return data.table
#' @keywords internal
#' @export
#' @examples
#' # Load example data
#' data("gd_GHI_2009_income")
Expand Down
62 changes: 51 additions & 11 deletions R/gd_compute_dist_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,27 @@ gd_estimate_dist_stats_lq <- function(mean, p0, A, B, C) {
# Compute Lorenz quadratic -----------------------------------------------

# Compute key numbers from Lorenz quadratic form
# Theorem 3 from original Lorenz quadratic paper
e <- -(A + B + C + 1) # e = -(A + B + C + 1): condition for the curve to go through (1, 1)
m <- (B^2) - (4 * A) # m < 0: condition for the curve to be an ellipse (m is called alpha in paper)
n <- (2 * B * e) - (4 * C) # n is called Beta in paper
r <- (n^2) - (4 * m * e^2) # r is called K in paper
kv <- gd_lq_key_values(A, B, C)

validity <- check_curve_validity_lq(A, B, C, e, m, n, r)

r <- sqrt(r)
s1 <- (r - n) / (2 * m)
s2 <- -(r + n) / (2 * m)
validity <- check_curve_validity_lq(A,
B,
C,
kv$e,
kv$m,
kv$n,
kv$r^2)

# Compute distributional measures -----------------------------------------

dist_stats <- gd_compute_dist_stats_lq(mean, p0, A, B, C, e, m, n, r)
dist_stats <- gd_compute_dist_stats_lq(mean,
p0,
A,
B,
C,
kv$e,
kv$m,
kv$n,
kv$r)

out <- list(
mean = mean,
Expand All @@ -142,6 +148,40 @@ gd_estimate_dist_stats_lq <- function(mean, p0, A, B, C) {
return(out)
}


#' gd_lq_key_values
#' Get key values in Table 2 of Datt (1998) paper
#' @inheritParams gd_estimate_lq
#' @return list
#' @export
gd_lq_key_values <- function(A, B, C) {

# Theorem 3 from original Lorenz quadratic paper
e <- -(A + B + C + 1) # e = -(A + B + C + 1): condition for the curve to go through (1, 1)
m <- (B^2) - (4 * A) # m < 0: condition for the curve to be an ellipse (m is called alpha in paper)
n <- (2 * B * e) - (4 * C) # n is called Beta in paper
r <- sqrt((n^2) - (4 * m * e^2)) # r is called K in paper


s1 <- (r - n) / (2 * m)
s2 <- -(r + n) / (2 * m)

# ____________________________________________________________________________
# Return ####
l_res <- list(
e = e,
m = m,
n = n,
r = r,
s1 = s1,
s2 = s2
)
return(l_res)

}



#' Estimates distributional stats from beta Lorenz fit
#' @inheritParams gd_estimate_lb
#' @return list
Expand Down
Loading

0 comments on commit d16d6a2

Please sign in to comment.