################################################################################
#
#' Calculate poverty indicators based on the Poverty Probability Index (PPI).
#'
#' @param surveyData A data frame containing informatiom to be used for
#' calculating the Poverty Probability Index (PPi)
#' @param index A numeric vector of length equal to \code{surveyData} containing
#' data on the calculated PPI score
#' @param ccode Three letter ISO code for a country
#' @param ppiTable Name of country PPI table to use from the ppitables package
#' @return A data frame containing calculated PPI scores, corresponding poverty
#' probabilities and wealth quintile
#' @examples
#' ppiMatrixBGD <- washdata::ppiMatrixBGD
#' povertyDF <- get_poverty_vars(surveyData = washdata::surveyDataBGD,
#' index = ppi,
#' ccode = "BGD",
#' ppiTable = ppitables::ppiBGD2013)
#'
#' @export
#'
#'
#
################################################################################
get_poverty_vars <- function(surveyData, index, ccode, ppiTable) {
## Calculate PPI score
ppi <- ppicalc::score_ppi_cohort(data = surveyData, ccode = ccode)
## Determine poverty probabilities
povertyDF <- ppicalc::get_ppi_cohort(index = ppi, ppiTable = ppiTable)
## Get quintile cut-offs
qCutOff <- quantile(ppi, probs = c(0.2, 0.4, 0.6, 0.8, 1))
## Classify households by wealth quintile
pQuintile <- ifelse(ppi <= qCutOff[1], 1,
ifelse(ppi > qCutOff[1] & ppi <= qCutOff[2], 2,
ifelse(ppi > qCutOff[2] & ppi <= qCutOff[3], 3,
ifelse(ppi > qCutOff[3] & ppi <= qCutOff[4], 4, 5))))
## Create povertyDF
povertyDF <- data.frame("uniqueID" = surveyData[ , "uniqueID"], ppi,
pQuintile, povertyDF)
## Return output
return(povertyDF)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.