DI: Diversity Index

View source: R/Categorical_Data_Functions.R

DIR Documentation

Diversity Index

Description

Computes a diversity index for a categorical variable, in either unstandardized or standarized form.

Usage

DI(x, std = FALSE, verbose = FALSE, digits = NULL)

Arguments

x

A vector with counts for each of k categories, e.g. output from running table() on a vector.

std

A logical value controlling whether the function returns the standarized diversity index (I). It defaults to FALSE, which returns the unstandardized diversity index (D).

verbose

A logical value controling whether or not to print output to the screen (D, I, N, k, & upper limit of D)

digits

An integer specifying the number of decimal places used when rounding the result. Defaults to NULL, which does not round the result.

Details

=============================================================================

This function implements the diversity index discussed by Agresti and Agresti (1978) for a categorical variable with k categories and sample size of N. The unstandardized form is called D, while the standardized form is called I. In the verbose output, Dlim is the upper limit of possible D values.

Value

A numeric value for the diversity index.

References

Agresti, A., & Agresti, B. F. (1978). Statistical analysis of qualitative variation. Sociological Methodology, 9, 204-237. doi:10.2307/270810

Examples

test1 <- c(A = 12, B = 0, C = 0, D = 0)
test2 <- c(A = 3, B = 3, C = 3, D = 3)
test3 <- c(A = 2, B = 4, C = 5, D = 1)
DI(test1, verbose = TRUE)
DI(test2, verbose = TRUE, digits = 3)
DI(test3, std = TRUE, verbose = TRUE)


sjpierce/piercer documentation built on Dec. 30, 2024, 3:28 p.m.