통계적 사고 (2판) 연습문제 (thinkstats2.com, think-stat.xwmooc.org)
Allen Downey / 이광춘(xwMOOC)

여성 응답자 파일을 읽어들여 변수명을 표시하시오.


In [2]:
%matplotlib inline

import chap01soln
resp = chap01soln.ReadFemResp()
resp.columns


Out[2]:
Index([u'caseid', u'rscrinf', u'rdormres', u'rostscrn', u'rscreenhisp',
       u'rscreenrace', u'age_a', u'age_r', u'cmbirth', u'agescrn',
       ...
       u'pubassis_i', u'basewgt', u'adj_mod_basewgt', u'finalwgt', u'secu_r',
       u'sest', u'cmintvw', u'cmlstyr', u'screentime', u'intvlngth'],
      dtype='object', length=3087)

응답자 가족에 대한 총소득 totincr 히스토그램을 생성하시오. 코드를 해석하기 위해서, codebook을 살펴보시오.


In [3]:
import thinkstats2
hist = thinkstats2.Hist(resp.totincr)

히스토그램을 화면에 표시하시오.


In [4]:
import thinkplot
thinkplot.Hist(hist, label='totincr')
thinkplot.Show()


<matplotlib.figure.Figure at 0xaee60aac>

인터뷰 당시 응답자 나이 변수, age_r에 대한 히스토그램을 생성하시오.


In [7]:
hist = thinkstats2.Hist(resp.age_r)
thinkplot.Hist(hist, label='age_r')
thinkplot.Show()


<matplotlib.figure.Figure at 0xaeacbd2c>

응답자 가구의 가구원수, numfmhh에 대한 히스토그램을 생성하시오.


In [8]:
hist = thinkstats2.Hist(resp.numfmhh)
thinkplot.Hist(hist, label='numfmhh')
thinkplot.Show()


<matplotlib.figure.Figure at 0xaeac32ec>

응답자가 낳은 자녀수, parity에 대한 히스토그램을 생성하시오. 이 분포를 어떻게 기술할까요?


In [9]:
hist = thinkstats2.Hist(resp.parity)
thinkplot.Hist(hist, label='parity')
thinkplot.Show()


<matplotlib.figure.Figure at 0xaebe3d4c>

Hist.Largest를 사용해서 parity의 가장 큰 수를 찾으시오.


In [12]:
print('The largest parity is ...', hist.Largest(10))


('The largest parity is ...', [(22, 1), (16, 1), (10, 3), (9, 2), (8, 8), (7, 15), (6, 29), (5, 95), (4, 309), (3, 828)])

totincr를 사용해서 가장 높은 임금을 갖는 응답자를 고르시오. 고임금 응답자에 대해서만 parity 분포를 계산하시오.


In [24]:
resp.totincr.value_counts() ## 총임금 빈도수 계산
rich = resp[resp.totincr == 14]
hist = thinkstats2.Hist(rich.parity)
thinkplot.Hist(hist, label='rich parity')
thinkplot.Show()


<matplotlib.figure.Figure at 0xaebbc08c>

고임금 응답자에 대한 가장 큰 parity를 구하시오.


In [26]:
hist.Largest(10)


Out[26]:
[(8, 1), (7, 1), (5, 5), (4, 19), (3, 123), (2, 267), (1, 229), (0, 515)]

고임금과 고임금이 아닌 집단에 대한 평균 parity를 비교하시오.


In [27]:
rich = resp[resp.totincr == 14]
poor = resp[resp.totincr < 14]
print('Rich mean value is: ', rich.parity.mean())
print('Poor mean value is: ', poor.parity.mean())


('Rich mean value is: ', 1.0758620689655172)
('Poor mean value is: ', 1.2495758136665125)

다른 흥미로워 보이는 변수도 조사하시오.


In [28]:
hist = thinkstats2.Hist(resp.fmarno)
thinkplot.Hist(hist, label='famrno')
thinkplot.Show()


<matplotlib.figure.Figure at 0xaf124f8c>

In [ ]: