entropy: Theil's Index of Entropy

Description Usage Arguments Value Source See Also Examples

View source: R/multi_group_measures.R

Description

Entropy is used to measure the the extent to which multiple distributions conform to a baseline.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
entropy(
  ...,
  population = NA,
  comparison = NULL,
  entropy_type = "entropy",
  logBase = exp(1),
  scale = FALSE,
  summed = FALSE,
  na.rm = TRUE,
  weights = NA,
  sumPercent = 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 ...

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.

entropy_type

One of:

"entropy"

Default. Ei = Σ (Xim \* ln(1/X_{im})) where Xim is the proportion of racial group within the geography i.

"information_theory"

Theil's information theory index

"overall_entropy"

Overall entropy for the summarized dataset. Reports one score for the entire dataset, as when setting summed=TRUE.

logBase

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

scale

Scale entropy scores from 0-1. Setting scale to TRUE ignores the entropy_type (set to "entropy") and summed parameters.

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).

na.rm

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

weights

deprecated, use population.

sumPercent

deprecated, will throw error.

Value

A single value if summed==TRUE, or a vector equaling the length of the inputs. Note that if entropy_type == "index", and summed is FALSE, then the returned vector will be entropy index, unweighted by population

Source

Theil, Henri. 1972. Statistical Decomposition Analysis.

See Also

https://en.wikipedia.org/wiki/Generalized_entropy_index

Examples

1
2
3
library(rsegregation)
entropy(bay_race$white,bay_race$hispanic,bay_race$asian,
bay_race$black, bay_race$all_other, population = bay_race$total_pop)

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