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 dep_var. The default (NULL) is equivalent to weights = rep(1, length(dep_var)).

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 custom_rif_function needs to be provided.

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 statistic = "quantiles".

custom_rif_function

the RIF function to compute the RIF of the custom distributional statistic. Default is NULL. Only needs to be provided if statistic = "custom". Every custom_rif_function needs the parameters dep_var, weights and probs. If they are not needed they must be set to NULL in the function definition (e.g. probs = NULL). A custom function must return a data frame containing at least a "rif" and "weights" column. See examples for further details.

...

additional parameters passed to the custom_rif_function. Apart from dep_var, weights and probs they must have a different name than the the ones in rif. For instance, if you want to pass a parameter statistic to the custom_rif_function, name it custom_statistic.

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
)


[Package rifreg version 0.1.0 Index]