Description Usage Arguments Details Value Source Examples
View source: R/multi_group_measures.R
Elizabeth Roberto's Divergence index for calculating and decomposing segregation.
1 2 3 4 5 6 7 8 9 10 11 |
... |
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 |
If TRUE, will return a single summary statistic. (Or one value per group if specifying
|
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 |
weights |
deprecated, use population. |
rowTotals, sumPercent |
deprecated, will throw error. |
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.
A single value if summed==TRUE, or a vector equaling the length of the inputs.
Created by Elizabeth Roberto: https://arxiv.org/abs/1508.01167
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.