Exercise from Think Stats, 2nd Edition (thinkstats2.com)
Allen Downey
Read the pregnancy file.
In [1]:
%matplotlib inline
import nsfg
preg = nsfg.ReadFemPreg()
Select live births, then make a CDF of totalwgt_lb.
In [ ]:
In [57]:
Display the CDF.
In [43]:
Find out how much you weighed at birth, if you can, and compute CDF(x).
In [44]:
Out[44]:
If you are a first child, look up your birthweight in the CDF of first children; otherwise use the CDF of other children.
In [59]:
Out[59]:
Compute the percentile rank of your birthweight
In [46]:
Out[46]:
Compute the median birth weight by looking up the value associated with p=0.5.
In [45]:
Out[45]:
Compute the interquartile range (IQR) by computing percentiles corresponding to 25 and 75.
In [47]:
Out[47]:
Make a random selection from cdf.
In [48]:
Out[48]:
Draw a random sample from cdf.
In [49]:
Out[49]:
Draw a random sample from cdf, then compute the percentile rank for each value, and plot the distribution of the percentile ranks.
In [50]:
Generate 1000 random values using random.random() and plot their PMF.
In [55]:
Assuming that the PMF doesn't work very well, try plotting the CDF instead.
In [56]:
In [60]:
In [64]:
Out[64]:
In [ ]: