get_rif {rifreg} | R Documentation |
Estimate Recentered Influence Functions
Description
This function estimates the recentered influence function (RIF) of a chosen distributional statistic (e.g. quantiles, variance or gini).
Usage
get_rif(
dep_var,
weights = NULL,
statistic,
probs = NULL,
custom_rif_function = NULL,
...
)
Arguments
dep_var |
dependent variable of distributional function. Discrete or continuous numeric vector. |
weights |
numeric vector of non-negative observation weights, hence of same length as |
statistic |
string containing the distributional statistic for which to compute the RIF. Can be one of
"mean", "variance", "quantiles", "gini", "interquantile_range", "interquantile_ratio", or "custom". If "custom"
is selected a |
probs |
a vector of length 1 or more with quantile positions to calculate the RIF.
Each quantile is indicated with value between 0 and 1. Only required if |
custom_rif_function |
the RIF function to compute the RIF of the custom distributional statistic.
Default is NULL. Only needs to be provided if |
... |
additional parameters passed to the |
Value
a data frame with the RIF value for each observation and in the case of several quantiles a column for each quantile.
References
Firpo, Sergio P., Nicole M. Fortin, and Thomas Lemieux. 2009. “Unconditional Quantile Regressions.” Econometrica 77(3): 953–73.
Cowell, Frank A., and Emmanuel Flachaire. 2015. “Statistical Methods for Distributional Analysis.” In Anthony B. Atkinson and François Bourguignon (eds.), Handbook of Income Distribution. Amsterdam: Elsevier.
Examples
dep_var <- c(1, 3, 9, 16, 3, 7, 4, 9)
probs <- seq(1:9) / 10
weights <- c(2, 1, 3, 4, 4, 1, 6, 3)
rif <- get_rif(
dep_var = dep_var,
weights = weights,
statistic = "quantiles",
probs = probs
)
# custom function
custom_variance_function <- function(dep_var, weights, probs = NULL) {
weighted_mean <- weighted.mean(x = dep_var, w = weights)
rif <- (dep_var - weighted_mean)^2
rif <- data.frame(rif, weights)
names(rif) <- c("rif_variance", "weights")
return(rif)
}
set.seed(123)
dep_var <- rlnorm(100)
weights <- rep(1, 100)
# custom function top 10% percent income share
# (see Essam-Nassah & Lambert, 2012, and Rios-Avila, 2020)
custom_top_income_share_function <- function(dep_var, weights, probs = 0.1) {
probs <- 1 - probs
weighted_mean <- weighted.mean(x = dep_var, w = weights)
weighted_quantile <- Hmisc::wtd.quantile(x = dep_var, weights = weights, probs = probs)
lorenz_ordinate <-
sum(dep_var[which(dep_var <= weighted_quantile)] *
weights[which(dep_var <= weighted_quantile)]) / sum(dep_var * weights)
if_lorenz_ordinate <- -(dep_var / weighted_mean) * lorenz_ordinate +
ifelse(dep_var < weighted_quantile,
dep_var - (1 - probs) * weighted_quantile,
probs * weighted_quantile
) / weighted_mean
rif_top_income_share <- (1 - lorenz_ordinate) - if_lorenz_ordinate
rif <- data.frame(rif_top_income_share, weights)
names(rif) <- c("rif_top_income_share", "weights")
return(rif_top_income_share)
}
rif_custom <- get_rif(
dep_var = dep_var,
weights = weights,
statistic = "custom",
custom_rif_function = custom_variance_function
)