Skip to content

Instantly share code, notes, and snippets.

@statkclee
Created November 28, 2015 12:45
Show Gist options
  • Save statkclee/09023b27443c1b420bad to your computer and use it in GitHub Desktop.
Save statkclee/09023b27443c1b420bad to your computer and use it in GitHub Desktop.
Think Stats 2, 1장 연습문제
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"통계적 사고 (2판) 연습문제 ([thinkstats2.com](thinkstats2.com), [think-stat.xwmooc.org](http://think-stat.xwmooc.org))<br>\n",
"Allen Downey / 이광춘(xwMOOC)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import nsfg\n",
"df = nsfg.ReadFemPreg()\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<tt>birthord</tt>에 대한 빈도수를 출력하고 [codebook](http://www.icpsr.umich.edu/nsfg6/Controller?displayPage=labelDetails&fileCode=PREG&section=A&subSec=8016&srtLabel=611933) 게시된 결과값과 비교하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df.birthord.value_counts().sort_index()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<tt>prglngth</tt>에 대한 빈도수를 출력하고 [codebook](http://www.icpsr.umich.edu/nsfg6/Controller?displayPage=labelDetails&fileCode=PREG&section=A&subSec=8016&srtLabel=611931) 게시된 결과값과 비교하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<tt>agepreg</tt>에 대한 빈도수를 출력하고 [codebook](http://www.icpsr.umich.edu/nsfg6/Controller?displayPage=labelDetails&fileCode=PREG&section=A&subSec=8016&srtLabel=611935)에 게시된 결과값과 비교하시오.\n",
"\n",
"이 데이터를 살펴보고, 응답자에 대한 존경과 맥락을 고려해서 데이터에 접근하는에 필요한 의무에 관해서 저자가 언급한 논평을 기억하라."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"평균 출생체중(birthweight)을 계산하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df.totalwgt_lb.mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"킬로그램으로 출생체중 정보를 담는 <tt>totalwgt_kg</tt>로 불리는 새로운 칼럼을 생성하라. 평균도 계산하시오. 새로운 칼럼을 생성할 때, 점표기법이 아닌 딕셔너리 구문을 사용하는 것을 기억하라."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"코드북(codebook)을 살펴보고 책에서 언급된 것이 아닌 본인이 관심있는 변수를 찾아내라. 그리고 그 변수의 빈도수, 평균, 다른 통계량을 계산하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"부울 시리즈(boolean Series)를 생성하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df.outcome == 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"부울 시리즈를 사용해서 정상출산 임신에 대한 레코드를 선택하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"live = df[df.outcome == 1]\n",
"len(live)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<tt>birthwgt_lb</tt> 변수에 0 에서 5 파운드(0과 5도 모두 포함) 사이 정상출산 빈도수를 계산하시오. 결과는 1125 가 되어야만 된다."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"len(live[(live.birthwgt_lb >= 0) & (live.birthwgt_lb <= 5)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<tt>birthwgt_lb</tt> 변수에 9 에서 95 파운드(9과 95도 모두 포함) 사이 정상출산 빈도수를 계산하시오. 결과는 798 가 되어야만 된다."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<tt>birthord</tt> 변수를 사용해서, 첫번째 아이와 첫째가 아닌 아이에 대한 레코드를 선택하시오. 첫번째 아이와 첫째가 아닌 아이는 얼마나 되는가?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"firsts = df[df.birthord==1]\n",
"others = df[df.birthord>1]\n",
"len(firsts), len(others)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"첫번째 아이와 첫째가 아닌 아이에 대한 평균 체중을 계산하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"firsts.totalwgt_lb.mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"others.totalwgt_lb.mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"변수 <tt>prglngth</tt>으로 첫째 아이와 첫째가 아닌 아이에 대한 평균임신기간을 계산하시오. 시간으로 표시된, 평균에 차이를 계산하시오."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment