HW 06 - Smoking during pregnancy

Homework
Modified

March 20, 2025

Important

This homework is due March 26 at 11:59pm.

Learning objectives

  • Construct confidence intervals
  • Conduct hypothesis tests
  • Interpret confidence intervals and results of hypothesis tests in context of the data

Getting started

  • Go to the info2951-sp25 organization on GitHub. Click on the repo with the prefix hw-06. It contains the starter documents you need to complete the homework.

  • Clone the repo and start a new project in RStudio. See the Lab 0 instructions for details on cloning a repo and starting a new R project.

General guidance

Guidelines + tips

As we’ve discussed in lecture, your plots should include an informative title, axes should be labeled, and careful consideration should be given to aesthetic choices.

Remember that continuing to develop a sound workflow for reproducible data analysis is important as you complete the lab and other assignments in this course. There will be periodic reminders in this assignment to remind you to render, commit, and push your changes to GitHub. You should have at least 3 commits with meaningful commit messages by the end of the assignment.

Workflow + formatting

Make sure to

  • Update author name on your document.
  • Label all code chunks informatively and concisely.
  • Follow the Tidyverse code style guidelines.
  • Make at least 3 commits.
  • Resize figures where needed, avoid tiny or huge plots.
  • Turn in an organized, well formatted document.

Packages

We’ll use the {tidyverse} package for much of the data wrangling and visualization, the {tidymodels} package for modeling and inference, and the data lives in the {openintro} package. These packages are already installed for you. You can load them by running the following in your Console:

Data

Every year, the US releases to the public a large data set containing information on births recorded in the country. This data set has been of interest to medical researchers who are studying the relation between habits and practices of expectant mothers and the birth of their children. This is a random sample of 1,000 cases from the data set released in 2014.

The data can be found in the {openintro} package, and it’s called births14. Since the dataset is distributed with the package, we don’t need to load it separately; it becomes available to us when we load the package. You can find out more about the dataset by inspecting its documentation, which you can access by running ?births14 in the Console or using the Help menu in RStudio to search for births14. You can also find this information here.

Set a seed!

In this lab we’ll be generating random samples. The last thing you want is those samples to change every time you render your document. So, you should set a seed. There’s an R chunk in your Quarto file set aside for this. Locate it and add a seed. Make sure all members in a team are using the same seed so that you don’t get merge conflicts and your results match up for the narratives.

Exercises

Exercise 1

What are the cases in this data set? How many cases are there in our sample?

The first step in the analysis of a new dataset is getting acquainted with the data. Make summaries of the variables in your dataset, determine which variables are categorical and which are numerical. For numerical variables, are there outliers? If you aren’t sure or want to take a closer look at the data, make a graph.

Exercise 2

A 1995 study suggests that average weight of Caucasian babies born in the US is 3,369 grams (7.43 pounds).1 In this dataset we only have information on mother’s race, so we will make the simplifying assumption that babies of Caucasian mothers are also Caucasian, i.e. whitemom = "white".

1 Wen, Shi Wu, Michael S. Kramer, and Robert H. Usher. “Comparison of birth weight distributions between Chinese and Caucasian infants.” American Journal of Epidemiology 141.12 (1995): 1177-1187.

We want to evaluate whether the average weight of Caucasian babies has changed since 1995.

Our null hypothesis should state “there is nothing going on”, i.e. no change since 1995:

\[H_0: \mu = 7.43~\text{pounds}\]

Our alternative hypothesis should reflect the research question, i.e. some change since 1995. Since the research question doesn’t state a direction for the change, we use a two sided alternative hypothesis:

\[H_A: \mu \ne 7.43~\text{pounds}\]

Create a filtered data frame called births14_white that contain data only from white mothers. Then, calculate the mean of the weights of their babies. Run the appropriate hypothesis test, visualize the null distribution, calculate the p-value, and interpret the results in context of the data and the hypothesis test.

Tip

For all hypothesis tests in this lab, use \(\alpha = 0.05\).

Exercise 3

Consider the possible relationship between a mother’s smoking habit and the weight of her baby. Plotting the data is a useful first step because it helps us quickly visualize trends, identify strong associations, and develop research questions.

Draw a boxplot displaying the relationship between habit and weight for all birth mothers (i.e. not just white mothers). What does the plot highlight about the relationship between these two variables?

Tip

Before moving forward, save a version of the dataset omitting observations where there are NAs for habit. You can call this version births14_habitgiven.

Exercise 4

The box plots show how the medians of the two distributions compare, but we can also compare the means of the distributions using the following to first group the data by the habit variable, and then calculate the mean weight in these groups using.

births14_habitgiven |>
  group_by(habit) |>
  summarize(mean_weight = mean(weight))

There is an observed difference, but is this difference statistically significant? In order to answer this question we will conduct a hypothesis test.

Write the hypotheses for testing if the average weights of babies born to smoking and non-smoking mothers are different. Run the appropriate hypothesis test, calculate the p-value, and interpret the results in context of the data and the hypothesis test.

Construct a 95% confidence interval for the difference between the average weights of babies born to smoking and non-smoking mothers. Would you expect the 95% confidence interval to contain 0? Why or why not?

Exercise 5

In this portion of the analysis we focus on a possible relationship between a mother’s maturity (mature) and the whether or not her baby has a low birth weight (lowbirthweight).

First, a non-inference task: Determine the age cutoff for younger and mature mothers. How are mothers classified as mature or young?

Once you have distinguished between younger and mature mothers, conduct a hypothesis test evaluating whether the proportion of low birth weight babies is higher for mature mothers. State the hypotheses, verify the conditions, run the test and calculate the p-value, and state your conclusion in context of the research question. If you find a significant difference, construct a confidence interval, at the equivalent level to the hypothesis test, for the difference between the proportions of low birth weight babies between mature and younger mothers, and interpret this interval in context of the data.

Wrap up

Submission

  • Go to http://www.gradescope.com and click Log in in the top right corner.
  • Click School Credentials \(\rightarrow\) Cornell University NetID and log in using your NetID credentials.
  • Click on your INFO 2951 course.
  • Click on the assignment, and you’ll be prompted to submit it.
  • Mark all the pages associated with exercise. All the pages of your homework should be associated with at least one question (i.e., should be “checked”).
  • Select all pages of your .pdf submission to be associated with the “Workflow & formatting” question.

Grading

Component Points
Ex 1 5
Ex 2 10
Ex 3 10
Ex 4 10
Ex 5 10
Workflow & formatting 5
Total 50
Workflow & formatting criteria

The “Workflow & formatting” component assesses the reproducible workflow. This includes:

  • At least 3 informative commit messages
  • Following {tidyverse} code style
  • All code being visible in rendered PDF without automatic wrapping (no more than 80 characters)
  • Ensuring reproducibility by setting a random seed value.

Acknowledgments