Skip to main content

Exercises 4.7 Exercises

1. Exercise 4.1.

How much did you weigh at birth? If you don’t know, call your mother or someone else who knows. And if no one knows, you can use my birth weight, 8.5 pounds, for this exercise.
Using the NSFG data (all live births), compute the distribution of birth weights and use it to find your percentile rank. If you were a first baby, find your percentile rank in the distribution for first babies. Otherwise use the distribution for others. If you are in the 90th percentile or higher, call your mother back and apologize.
Listing 4.7.1. Python Code
from nsfg import get_nsfg_groups

live, firsts, others = get_nsfg_groups()

2. Exercise 4.2.

For live births in the NSFG dataset, the column babysex indicates whether the baby was male or female. We can use query to select the rows for male and female babies.
Listing 4.7.2. Python Code
$ male = live.query("babysex == 1")
female = live.query("babysex == 2")
len(male), len(female)
(4641, 4500)
Make Cdf objects that represent the distribution of birth weights for male and female babies. Plot the two CDFs. What are the differences in the shape and location of the distributions?
If a male baby weighs 8.5 pounds, what is his percentile rank? What is the weight of a female baby with the same percentile rank?

3. Exercise 4.3.

From the NSFG dataset pregnancy data, select the agepreg column and make a Cdf to represent the distribution of age at conception for each pregnancy. Use the CDF to compute the percentage of ages less than or equal to 20, and the percentage less than or equal to 30. Use those results to compute the percentage between 20 and 30.
Listing 4.7.3. Python Code
from nsfg import read_fem_preg

preg = read_fem_preg()

4. Exercise 4.4.

Here are the running speeds of the people who finished the James Joyce Ramble, described earlier in this chapter.
Listing 4.7.4. Python Code
speeds = results["MPH"].values
Make a Cdf that represents the distribution of these speeds, and use it to compute the median, IQR, and quartile skewness. Does the distribution skew to the left or right?

5. Exercise 4.5.

The numbers generated by np.random.random are supposed to be uniform between 0 and 1, which means that the CDF of a sample should be a straight line. Let’s see if that’s true.
Listing 4.7.5. Python Code
t = np.random.random(1001)
Plot the CDF of this sample. Does it look like a straight line?