R/md_compute_mld.R

Defines functions md_compute_mld

Documented in md_compute_mld

#' Mean Log Deviation
#'
#' Given a vector of weights and welfare, this functions computes the
#' Mean Log Deviation (MLD).
#'
#' @inheritParams md_compute_dist_stats
#' @inheritParams md_compute_gini
#' @return numeric
#' @examples
#' wbpip:::md_compute_mld(welfare = 1:2000, weight = rep(1, 2000))
#' @export
md_compute_mld <- function(welfare, weight, mean = NULL) {

  # Compute MLD
  if (is.null(mean)) {
    mean <- fmean(x = welfare, w = weight)
  }

  welfare[welfare <= 0] <- 1 # this should be done before the mean
  deviation <- log(mean / welfare)
  mld <- fmean(
    x = deviation,
    w = weight
  )
  return(mld)
}
PIP-Technical-Team/wbpip documentation built on Nov. 29, 2024, 6:57 a.m.