통계적 사고 (2판) 연습문제 (thinkstats2.com, think-stat.xwmooc.org)
Allen Downey / 이광춘(xwMOOC)
여성 응답자 파일을 읽어들여 변수명을 표시하시오.
In [2]:
%matplotlib inline
import chap01soln
resp = chap01soln.ReadFemResp()
resp.columns
Out[2]:
응답자 가족에 대한 총소득 totincr 히스토그램을 생성하시오. 코드를 해석하기 위해서, codebook을 살펴보시오.
In [3]:
import thinkstats2
hist = thinkstats2.Hist(resp.totincr)
히스토그램을 화면에 표시하시오.
In [4]:
import thinkplot
thinkplot.Hist(hist, label='totincr')
thinkplot.Show()
인터뷰 당시 응답자 나이 변수, age_r에 대한 히스토그램을 생성하시오.
In [7]:
hist = thinkstats2.Hist(resp.age_r)
thinkplot.Hist(hist, label='age_r')
thinkplot.Show()
응답자 가구의 가구원수, numfmhh에 대한 히스토그램을 생성하시오.
In [8]:
hist = thinkstats2.Hist(resp.numfmhh)
thinkplot.Hist(hist, label='numfmhh')
thinkplot.Show()
응답자가 낳은 자녀수, parity에 대한 히스토그램을 생성하시오. 이 분포를 어떻게 기술할까요?
In [9]:
hist = thinkstats2.Hist(resp.parity)
thinkplot.Hist(hist, label='parity')
thinkplot.Show()
Hist.Largest를 사용해서 parity의 가장 큰 수를 찾으시오.
In [12]:
print('The largest parity is ...', hist.Largest(10))
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()
고임금 응답자에 대한 가장 큰 parity를 구하시오.
In [26]:
hist.Largest(10)
Out[26]:
고임금과 고임금이 아닌 집단에 대한 평균 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())
다른 흥미로워 보이는 변수도 조사하시오.
In [28]:
hist = thinkstats2.Hist(resp.fmarno)
thinkplot.Hist(hist, label='famrno')
thinkplot.Show()
In [ ]: