Skip to content

Instantly share code, notes, and snippets.

@nogawanogawa
Last active August 29, 2021 14:59
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 nogawanogawa/30c98b620f662bfcc939c1aa4cc6f2b2 to your computer and use it in GitHub Desktop.
Save nogawanogawa/30c98b620f662bfcc939c1aa4cc6f2b2 to your computer and use it in GitHub Desktop.
fisher_exact.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Untitled22.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyNcKMd7x6VO5McODbT+VMQF",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/nogawanogawa/30c98b620f662bfcc939c1aa4cc6f2b2/untitled22.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "YiM4e4zNeZmW"
},
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from scipy import stats"
],
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "sK3N0plNkiqQ",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 111
},
"outputId": "12dccce8-dec9-4691-d138-013360bec4d6"
},
"source": [
"data = pd.DataFrame({\n",
" \"true\":[291, 527],\n",
" \"false\":[120, 387],\n",
"},\n",
"index=['man', 'woman']\n",
")\n",
"data"
],
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>true</th>\n",
" <th>false</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>man</th>\n",
" <td>291</td>\n",
" <td>120</td>\n",
" </tr>\n",
" <tr>\n",
" <th>woman</th>\n",
" <td>527</td>\n",
" <td>387</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" true false\n",
"man 291 120\n",
"woman 527 387"
]
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "FoORrvHOjtoM",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "ba088650-bee0-46c8-df31-4b6838b75a8b"
},
"source": [
"_, p = stats.fisher_exact(data)\n",
"p"
],
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"4.5127166284269095e-06"
]
},
"metadata": {},
"execution_count": 3
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment