divergence: Divergence Index

Description Usage Arguments Details Value Source Examples

View source: R/multi_group_measures.R

Description

Elizabeth Roberto's Divergence index for calculating and decomposing segregation.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
divergence(
  ...,
  population = NA,
  na.rm = TRUE,
  summed = FALSE,
  logBase = exp(1),
  comparison = NULL,
  sumPercent = NA,
  weights = NA,
  rowTotals = NA
)

Arguments

...

Vectors containing proportions of each group, or a dataframe containing only those vectors.

population

A vector of population totals for each row, or weights summing to a total of one. If NA, will assume all populations/weights are equal. Set to 1 to silence warning. If a string, will use the string as the named column of the dataframe provided in ...

na.rm

logical. Should missing values (including NaN) be removed? Used only if summed is set to TRUE.

summed

If TRUE, will return a single summary statistic. (Or one value per group if specifying dplyr::group_by.) If FALSE (default), will return a vector equaling the length of the input vectors. If 'weighted' (only for divergence and information theory), returns a vector as in FALSE, but with pre-weighted values, such that sum(divergence(..., summed = 'weighted)) is equivalent to divergence(..., summed = T).

logBase

Specify the base for the logathirm used in the equation. Natural logarithm by default.

comparison

A vector of percentages that must equal the length of the number of vectors or columns in ..., representing the percentages of each group in the larger (comparison) geography.

weights

deprecated, use population.

rowTotals, sumPercent

deprecated, will throw error.

Details

The demographics of each observation are compared to that of their larger geography, which is inferred from the combination of the percentages in ... and the population totals in population, or can be directly provided with comparison.

Value

A single value if summed==TRUE, or a vector equaling the length of the inputs.

Source

Created by Elizabeth Roberto: https://arxiv.org/abs/1508.01167

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(rsegregation)
data("bay_race")
#return by-observation scores
divergence(bay_race$white,bay_race$hispanic,bay_race$asian,
bay_race$black, bay_race$all_other, population=bay_race$total_pop)

# Using dplyr
require(dplyr)
mutate(bay_race, divergence_score = divergence(white, hispanic,
  asian, black, all_other, population=total_pop))

# divergence alsow works with percentages as long as you have
# population totals by observation
bay_race %>%
  mutate_at(vars(hispanic:all_other), list(~(./total_pop))) %>%
  mutate(divergence_score = divergence(white, hispanic, asian,
  black, all_other, population = total_pop))

arthurgailes/rsegregation documentation built on May 23, 2021, 6:33 a.m.