Skip to main content

Exercises 11.7 Exercises

1. Exercise 11.1.

Are baby boys heavier than baby girls? To answer this question, we’ll use the NSFG data again.
Fit a linear regression model with totalwgt_lb as the response variable and babysex as a categorical explanatory variable -- the value of this variable is 1 for boys and 2 for girls. What is the estimated difference in weight? Is it statistically significant? What if you control for the mother’s age -- does maternal age account for some or all of the apparent difference?

2. Exercise 11.2.

The Trivers-Willard hypothesis suggests that for many mammals the sex ratio depends on "maternal condition" -- that is, factors like the mother’s age, size, health, and social status. Some studies have shown this effect among humans, but results are mixed.
Let’s see if there is a relationship between mother’s age and the probability of having a boy. Fit a logistic regression model with the baby’s sex as the response variable and mother’s age as an explanatory variable. Are older mothers more or less likely to have boys? What if you use a quadratic model of maternal age?
In order to use babysex as a response variable in a logistic regression, we’ll recode it with the value 1 for boys and 0 for girls.
Listing 11.7.1. Python Code
valid["y"] = (valid["babysex"] == 1).astype(int)

3. Exercise 11.3.

For the Adelie penguins, fit a linear regression model that predicts penguin weights as a function of flipper_length, culmen_depth, and Sex as a categorical variable. If we control for flipper length and culmen depth, how much heavier are male penguins? Generate and plot predictions for a range of flipper lengths, for male and female penguins, with culmen_depth set to its average value.

4. Exercise 11.4.

Let’s see if Chinstrap penguins are more or less dimorphic than the other penguin species in the dataset, as quantified by the pseudo \(R^2\) value of the model. Use get_species to select the Chinstrap penguins, then use logistic regression to fit a logistic regression model with sex as the response variable and all four measurements as explanatory variables. How does the pseudo \(R^2\) value compare to the other models?
Listing 11.7.2. Python Code
$ chinstrap = get_species(penguins, "Chinstrap")
len(chinstrap)
68