Last active
August 29, 2021 14:10
-
-
Save nogawanogawa/fc08dc0f791b159bc3cc08af22b5b0a0 to your computer and use it in GitHub Desktop.
chi-square.ipynb
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Untitled22.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyNq4JS7c3DV/g1N9S4HcMvG", | |
"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/fc08dc0f791b159bc3cc08af22b5b0a0/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": "92171d95-7034-40a9-cb69-386664b6cb19" | |
}, | |
"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": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "KSBPKcPNf0uW", | |
"outputId": "3cb53dc1-87f0-4958-b382-a1359c2d478f" | |
}, | |
"source": [ | |
"res = stats.chi2_contingency(data, correction=False)\n", | |
"print(res)" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"(20.735570925391748, 5.2727380569338135e-06, 1, array([[253.73433962, 157.26566038],\n", | |
" [564.26566038, 349.73433962]]))\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "FoORrvHOjtoM" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 3, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment