]> code.communitydata.science - rises_declines_wikia_code.git/blob - RCommunityData/R/hhi.R
Initial commit
[rises_declines_wikia_code.git] / RCommunityData / R / hhi.R
1 # Community Data Science Collective R Utilities
2 #
3 # Copyright (c) 2010-2016 Benjamin Mako Hill and Aaron Shaw 
4 # mako@atdot.cc, aaronshaw@northwestern.edu
5
6 ## functions to create normal and non-normalized herfenidahl indexes
7 hhi <- function (x) {
8   x <- x / sum(x)
9   sum(x**2)
10 }
11
12 hhi.norm <- function (x) {
13   n <- length(x)
14   h <- hhi(x)
15   (h - 1/n)/(1-1/n)
16 }
17

Community Data Science Collective || Want to submit a patch?