Created
August 3, 2016 03:52
-
-
Save tmcw/b459fd6550924186eae8c9c3537a3862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ss = require('simple-statistics'); | |
var fs = require('fs'); | |
var people = require('./people.json'); | |
var teams = people.reduce(function (memo, person) { | |
person.teams.forEach(function (team) { | |
if (memo[team] === undefined) memo[team] = []; | |
memo[team].push(person); | |
}); | |
return memo; | |
}, Object.create(null)); | |
function eq(x) { return function (y) { return x === y; }; } | |
// var firstColumn = ['0.90 0.95 0.975 0.99 0.995 0.999 | |
// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm | |
var pValues = fs.readFileSync('ttable.txt', 'utf8') | |
.split(/\n/) | |
.map(function (line) { | |
return parseFloat(line.split(/\s+/)[7]) | |
}); | |
var significant = []; | |
var insignificant = []; | |
Object.keys(teams).sort().forEach(function (team) { | |
var population = teams[team].map(function (person) { | |
return person.sex === 'xx' ? 0 : 1; | |
}); | |
var total = population.length; | |
var men = population.filter(eq(1)).length; | |
var women = population.filter(eq(0)).length; | |
var lean = women / total; | |
var leans = (lean > 0.5) ? | |
`${((lean - 0.5) * 200).toFixed(2)}% women` : | |
`${((0.5 - lean) * 200).toFixed(2)}% men`; | |
var tValue = ss.tTest(population, 0.5); | |
var pValue = pValues[total - 1]; | |
if (tValue > pValue) { | |
significant.push(`* The ${team} team has ${women} women and ${men} men (${total} total) | |
* Leans ${leans}`); | |
} else { | |
insignificant.push(`* The ${team} team has ${women} women and ${men} men (${total} total) | |
* Leans ${leans}`); | |
} | |
}); | |
console.log('# Significant\n\n' + significant.join('\n') + '\n'); | |
console.log('# Insignificant\n\n' + insignificant.join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment