Length of gestation

Application exercise

In this application exercise, we’ll do inference for a single mean, using simulation-based and mathematical models.

Packages

We’ll use the tidyverse, tidymodels, and openintro packages.

library(tidyverse)
library(tidymodels)
library(openintro)

Data

Every year, the United States Department of Health and Human Services releases to the public a large dataset containing information on births recorded in the country. This dataset 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. In this case study we work with a random sample of 1,000 cases from the dataset released in 2014. The length of pregnancy, measured in weeks, is commonly referred to as gestation.

glimpse(births14)
Rows: 1,000
Columns: 13
$ fage           <int> 34, 36, 37, NA, 32, 32, 37, 29, 30, 29, 30, 34, 28, 28,…
$ mage           <dbl> 34, 31, 36, 16, 31, 26, 36, 24, 32, 26, 34, 27, 22, 31,…
$ mature         <chr> "younger mom", "younger mom", "mature mom", "younger mo…
$ weeks          <dbl> 37, 41, 37, 38, 36, 39, 36, 40, 39, 39, 42, 40, 40, 39,…
$ premie         <chr> "full term", "full term", "full term", "full term", "pr…
$ visits         <dbl> 14, 12, 10, NA, 12, 14, 10, 13, 15, 11, 14, 16, 20, 15,…
$ gained         <dbl> 28, 41, 28, 29, 48, 45, 20, 65, 25, 22, 40, 30, 31, NA,…
$ weight         <dbl> 6.96, 8.86, 7.51, 6.19, 6.75, 6.69, 6.13, 6.74, 8.94, 9…
$ lowbirthweight <chr> "not low", "not low", "not low", "not low", "not low", …
$ sex            <chr> "male", "female", "female", "male", "female", "female",…
$ habit          <chr> "nonsmoker", "nonsmoker", "nonsmoker", "nonsmoker", "no…
$ marital        <chr> "married", "married", "married", "not married", "marrie…
$ whitemom       <chr> "white", "white", "not white", "white", "white", "white…

Bootstrap confidence intervals

Exercise 1

Construct and interpret a 95% confidence interval, using the standard error method with the get_ci() function, for the average length of gestation.

# add code here

Add response here.

Exercise 2

Construct the interval without using the get_ci() (or get_confidence_interval()) function.

# add code here

Exercise 3

Would you expect a 90% confidence interval for the average length of gestation to be wider or narrower? Explain your reasoning.

Add response here.

Exercise 4

Now construct a 90% confidence interval for the average length of gestation and confirm your answer from the previous exercise. Repeat as little of your code as possible.

# add code here

Confidence intervals with mathematical models

If technical conditions are satisfied, the distribution of the sampling mean (i.e., the sampling distribution) follows the t-distribution with n - 1 degrees of freedom, where n is the sample size.

sampling_dist <- births14 |>
  specify(response = weeks) |>
  assume(distribution = "t")

sampling_dist
A T distribution with 999 degrees of freedom.
visualize(sampling_dist)

Exercise 5

Construct and visualize a confidence interval using mathematical models for the average length of gestation.

# add code here