Last active
December 17, 2015 12:39
-
-
Save hitsumabushi/bda935a61ad989574141 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%reload_ext autoreload\n", | |
"%autoreload 2\n", | |
"\n", | |
"# ヒストグラムなどの表示のため\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[ 1.804 2.196]\n" | |
] | |
} | |
], | |
"source": [ | |
"# Q1\n", | |
"import numpy as np\n", | |
"n=100\n", | |
"ave = 2.0\n", | |
"s = 1.0\n", | |
"z = 1.96\n", | |
"\n", | |
"range = 2 + np.array([-z, z]) * s/np.sqrt(n)\n", | |
"\n", | |
"print(range)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"A : (0.57823641544501547, 0.92508848972329294)\nB : (0.043939011276519502, 0.36884859936045405)\nC : (-0.0091018716816653328, 0.25411451392920281)\n" | |
] | |
} | |
], | |
"source": [ | |
"# Q3\n", | |
"\n", | |
"n=20\n", | |
"A=16\n", | |
"B=3\n", | |
"C=1\n", | |
"\n", | |
"import statsmodels.stats.proportion as sm\n", | |
"A_hat = sm.proportion_confint(count=A, nobs=n, method=\"agresti_coull\")\n", | |
"print(\"A :\", A_hat)\n", | |
"B_hat = sm.proportion_confint(count=B, nobs=n, method=\"agresti_coull\")\n", | |
"C_hat = sm.proportion_confint(count=C, nobs=n, method=\"agresti_coull\")\n", | |
"print(\"B :\", B_hat)\n", | |
"print(\"C :\", C_hat)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"48018.2352587\n" | |
] | |
} | |
], | |
"source": [ | |
"# Q4.\n", | |
"import statsmodels.stats.proportion as sm\n", | |
"inf = sm.samplesize_confint_proportion(alpha=0.05, proportion=0.5, half_length=0.01)\n", | |
"print(inf * 1/0.2) # 0.2 : 返信率" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3.0 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment