Get grouped stats from the PIP API.

get_gd(
  cum_welfare,
  cum_population,
  estimate = c("stats", "lorenz", "params"),
  requested_mean = NULL,
  povline = NULL,
  popshare = NULL,
  lorenz = NULL,
  n_bins = NULL,
  api_version = "v1",
  format = c("rds", "json", "csv"),
  simplify = TRUE,
  server = NULL
)

Arguments

cum_welfare

numeric: Cumulative welfare values, expressed in shares. Any length. They should be monotonically increasing, and sum to 1.

cum_population

numeric: Cumulative population values, expressed in shares. Any length. They should be monotonically increasing, and sum to 1.

estimate

character: One of "stats", "lorenz", "params".

requested_mean

numeric: Requested mean.

povline

numeric: Poverty line. Required for estimate = "stats".

popshare

One numeric population share from 0 to 1, or NULL.

lorenz

character: Lorenz curve methodology. Either "lb" or "lq".

n_bins

numeric: Number of bins. Required for estimate = "lorenz".

api_version

API version. Currently only "v1" is supported.

format

Response format: "rds", "json", or "csv".

simplify

One non-missing logical value. If TRUE (the default), return simplified data.

server

One non-empty server name, or NULL for the production server. For World Bank internal use only.

Value

A data frame when simplify = TRUE, or a pip_api list when simplify = FALSE.

Examples

if (interactive()) {

datt_data <- data.frame(p = c(0.0092, 0.0339, 0.0850, 0.160, 0.2609, 0.4133,
                              0.5497, 0.7196, 0.8196, 0.9174, 0.9570, 0.9751,
                              1),
                       L = c(0.00208, 0.01013, 0.03122, 0.07083, 0.12808,
                             0.23498, 0.34887, 0.51994, 0.64270, 0.79201,
                             0.86966, 0.91277, 1))

# estimate = 'stats': retrieve poverty statistics.
stats <- get_gd(cum_welfare = datt_data$L, cum_population = datt_data$p,
                estimate = "stats",
                requested_mean = 19,
                povline = 2.15)

# estimate = 'lorenz': retrieve Lorenz curve data points for a specified number of bins.

## Best lorenz curve methodolody selected by default:
lorenz <- get_gd(cum_welfare = datt_data$L,
                 cum_population = datt_data$p,
                 estimate = "lorenz",
                 n_bins = 100)  # must be specified, default is NULL.

## Specify lorenz curve methodology:
### Beta Lorenz ("lb")
lorenz_lb <- get_gd(cum_welfare = datt_data$L,
                 cum_population = datt_data$p,
                 estimate = "lorenz",
                 lorenz = "lb",
                 n_bins = 100)

### Quadratic Lorenz ("lq")
lorenz_lq <- get_gd(cum_welfare = datt_data$L,
                 cum_population = datt_data$p,
                 estimate = "lorenz",
                 lorenz = "lq",
                 n_bins = 100)

# estimate = 'params': retrieve regression parameters used for the lorenz curve estimation.
params <- get_gd(cum_welfare = datt_data$L,
                 cum_population = datt_data$p,
                 estimate = "params")
}