Computes the B index for a vector of frequencies of categories.

B(x, na.rm = TRUE)

Arguments

x

a vector of frequencies

na.rm

if TRUE, missing values are removed. If FALSE, NA is returned if there is any NA value.

Value

The value of the B statistics, which is normalised (varies between 0 and 1).

Details

According to Wilcox (1973, p. 330), and following Kaiser (1968), the B index relies on the geometric mean, but corrects it for undesirable properties. The formula for the B index is: $$1 - \sqrt{1 - \left(\sqrt[K]{\prod_{i=1}^k \frac{f_i K}{N}}\right)^2}$$

References

Wilcox, Allen R. 'Indices of Qualitative Variation and Political Measurement.' The Western Political Quarterly 26, no. 2 (1 June 1973): 325-43. doi:10.2307/446831. Kaiser, Henry F. 'A Measure of the Population Quality of Legislative Apportionment.' The American Political Science Review 62, no. 1 (March 1968): 208. doi:10.2307/1953335.

Examples

x <- rmultinom(1, 100, rep_len(0.25, 4)) x <- as.vector(t(x)) B(x)
#> [1] 0.9516395
df <- rmultinom(10, 100, rep_len(0.25, 4)) df <- as.data.frame(t(df)) apply(df, 1, B)
#> [1] 0.8038745 0.9367316 0.8338673 0.6683070 0.9516395 0.9028882 0.8758279 #> [8] 0.8166392 0.9143287 0.8244215