Skip to content

Instantly share code, notes, and snippets.

@eyeseast
Created June 21, 2014 00:28
Show Gist options
  • Save eyeseast/a1288c5df88187b457f4 to your computer and use it in GitHub Desktop.
Save eyeseast/a1288c5df88187b457f4 to your computer and use it in GitHub Desktop.
A python implementation of the USA Today Diversity Index, first developed by Phil Meyer and Shawn McIntosh of USA Today in 1990; updated in 2000 by Meyer and Paul Overberg.
#!/usr/bin/env python
"""
A python implementation of the USA Today Diversity Index, first developed by
Phil Meyer and Shawn McIntosh of USA Today in 1990; updated in 2000 by Meyer
and Paul Overberg.
Source and explanation: http://ire.org/resource-center/tipsheets/3473/
"""
def simple(*categories):
"""
Calculate a simple diversity index score based on percent from categories.
Returns a score from 0 to 1, representing the likelihood that two people
chosen at random from the group are different from each other.
0: No diversity. Everyone is the same.
1: Perfect diversity. Everyone is different.
USA Today diversity index:
Diversity = 1 - ((W^2 + B^2 + AmIndI^2 + A^2 + PI^2) * (H^2 + Non-H^2))
This is a simplified version of that formula, assuming only one factor
(race, but not ethnicity, for example).
>>> round(simple(.8, .2), 2)
0.32
"""
return 1 - sum(c**2 for c in categories)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment