Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 3, 2016 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/b459fd6550924186eae8c9c3537a3862 to your computer and use it in GitHub Desktop.
Save tmcw/b459fd6550924186eae8c9c3537a3862 to your computer and use it in GitHub Desktop.
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