Exercise from Think Stats, 2nd Edition (thinkstats2.com)
Allen Downey

Read the female respondent file.


In [1]:
%matplotlib inline

import chap01soln
resp = chap01soln.ReadFemResp()

Make a PMF of numkdhh, the number of children under 18 in the respondent's household.


In [4]:
import thinkstats2 as ts

children_PMF = ts.Pmf(resp.numkdhh)

Display the PMF.


In [ ]:


In [1]:

Define BiasPmf.


In [2]:
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

Make a the biased Pmf of children in the household, as observed if you surveyed the children instead of the respondents.


In [2]:

Display the actual Pmf and the biased Pmf on the same axes.


In [2]:

Compute the means of the two Pmfs.


In [2]:


In [2]:


In [2]: