Calculate bins. TO BE DOCUMENTED.
Usage
get_bins(
.data,
welfare,
weight,
distribution_type = c("micro", "group", "aggregate", "imputed"),
nbins = 100,
output = "simple"
)
Arguments
- .data
Household survey data frame with at least a welfare variable.
- welfare
numeric: A vector of income or consumption values.
- weight
numeric: A vector of weights.
- distribution_type
character: Type of distribution, either micro, group, aggregate or imputed.
- nbins
numeric: Number of bins.
- output
character: It has two varieties. 1) it could be a vector of variables to retain after calculations (variables available are "welfare", "weight", "cum_pop", "cum_prop_pop", and "bins"). 2) It could be a one of two key words, "simple" or "full".
output = "simple"
is equivalent tooutput = "bins"
(which is the default).output = "full"
if equivalent to a vector with all the variables available,output = c("welfare", "weight", "cum_pop", "cum_prop_pop","bins")
Examples
data("md_ABC_2000_income")
df <- md_ABC_2000_income
bins <- get_bins(df, welfare, weight)
#> ℹ Data has been sorted by variable "welfare"
str(bins)
#> num [1:2000] 1 1 1 1 1 1 1 1 1 1 ...
#> - attr(*, "label")= chr "Quantiles"
bins <- get_bins(df, welfare, weight, output = "full")
str(bins)
#> Classes ‘data.table’ and 'data.frame': 2000 obs. of 5 variables:
#> $ welfare : num 0 64547 81078 83195 89137 ...
#> $ weight : num 66 279 180 105 37 ...
#> $ cum_pop : num 66 345 525 630 667 ...
#> ..- attr(*, "label")= chr "cumulative population"
#> $ cum_prop_pop: num 0.00012 0.000625 0.000951 0.001141 0.001208 ...
#> ..- attr(*, "label")= chr "cumulative proportion of population"
#> $ bins : num 1 1 1 1 1 1 1 1 1 1 ...
#> ..- attr(*, "label")= chr "Quantiles"
#> - attr(*, ".internal.selfref")=<externalptr>