#!/usr/bin/env python # coding: utf-8 # 통계적 사고 (2판) 연습문제 ([thinkstats2.com](thinkstats2.com), [think-stat.xwmooc.org](http://think-stat.xwmooc.org))
# Allen Downey / 이광춘(xwMOOC) # # 여성 응답자 파일을 읽어들인다. # In[19]: get_ipython().run_line_magic('matplotlib', 'inline') import chap01soln resp = chap01soln.ReadFemResp() # 응답자 가구에서 18세 이하 자녀수, numkdhh에 대한 PMF를 생성하라. # In[20]: import thinkstats2 pmf = thinkstats2.Pmf(resp.numkdhh) # PMF를 화면에 표시하라. # In[21]: import thinkplot thinkplot.Pmf(pmf, label='numkdhh') thinkplot.Show() # BiasPmf를 정의하시오. # In[22]: def BiasPmf(pmf, label=''): """Returns the Pmf with oversampling proportional to value. If pmf is the distribution of true values, the result is the distribution that would be seen if values are oversampled in proportion to their values; for example, if you ask students how big their classes are, large classes are oversampled in proportion to their size. Args: pmf: Pmf object. label: string label for the new Pmf. Returns: Pmf object """ new_pmf = pmf.Copy(label=label) for x, p in pmf.Items(): new_pmf.Mult(x, x) new_pmf.Normalize() return new_pmf # 응답자 대신에 자녀를 설문조사하면 관측되듯이, 가구 자녀수에 대한 편향된 Pmf를 생성하시오. # In[23]: biased = BiasPmf(pmf, label='biased') # 실제 Pmf와 편향된 Pmf를 동일축으로 화면에 표시하시오. # In[24]: thinkplot.PrePlot(2) thinkplot.Pmfs([pmf, biased]) thinkplot.Show() # 두 Pmf의 평균을 계산하시오. # In[25]: print('Pmf Mean: ',pmf.Mean()) print('Biased Pmf Mean', biased.Mean()) # In[ ]: