Skip to content

Instantly share code, notes, and snippets.

@kantale
Created March 2, 2019 18:48
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 kantale/8403df5d2826e662184cc9b8036bc0b3 to your computer and use it in GitHub Desktop.
Save kantale/8403df5d2826e662184cc9b8036bc0b3 to your computer and use it in GitHub Desktop.
Gender Bias FDR test regarding data from: https://twitter.com/meganinlisbon/status/1101870079858409478
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://twitter.com/meganinlisbon/status/1101870079858409478"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"FDR: 0.04426 Gender Bias: CONFIRMED\n"
]
}
],
"source": [
"import random\n",
"\n",
"women_succeed = 83\n",
"women_total = 264\n",
"men_succeed = 255\n",
"men_total = 677\n",
"\n",
"success = women_succeed + men_succeed\n",
"total = women_total + men_total\n",
"women_ratio = women_succeed / women_total\n",
"men_ratio = men_succeed / men_total\n",
"\n",
"found_difference = men_ratio - women_ratio\n",
"all_samples = ['♂']*men_total + ['♀']*women_total\n",
"\n",
"def random_trial():\n",
" all_success = random.sample(all_samples, success)\n",
" \n",
" random_women_s = sum(x=='♀' for x in all_success)\n",
" random_men_s = success - random_women_s\n",
" \n",
" random_women_s_ratio = random_women_s / women_total\n",
" random_men_s_ratio = random_men_s / men_total\n",
" \n",
" return random_men_s_ratio-random_women_s_ratio >= found_difference\n",
"\n",
"\n",
"trials = 100000\n",
"fdr = sum(random_trial() for x in range(trials))/trials\n",
"print ('FDR: {} Gender Bias: {}'.format(fdr, {True:'CONFIRMED', False: 'DISCONFIRMED'}[fdr<0.05]))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment