18 lines
361 B
R
18 lines
361 B
R
# Community Data Science Collective R Utilities
|
|
#
|
|
# Copyright (c) 2010-2016 Benjamin Mako Hill and Aaron Shaw
|
|
# mako@atdot.cc, aaronshaw@northwestern.edu
|
|
|
|
## functions to create normal and non-normalized herfenidahl indexes
|
|
hhi <- function (x) {
|
|
x <- x / sum(x)
|
|
sum(x**2)
|
|
}
|
|
|
|
hhi.norm <- function (x) {
|
|
n <- length(x)
|
|
h <- hhi(x)
|
|
(h - 1/n)/(1-1/n)
|
|
}
|
|
|