North Carolina births

In 2004, the state of North Carolina released a large data set containing information on births recorded in this state. This data set is useful to researchers studying the relation between habits and practices of expectant mothers and the birth of their children. We will work with a random sample of observations from this data set.

Exploratory analysis

Load the nc data set into our workspace.

nc = read.csv("https://www.openintro.org/stat/data/csv/ncbirths.csv")

We have observations on 13 different variables, some categorical and some numerical. The meaning of each variable is as follows.

variable description
fage father’s age in years.
mage mother’s age in years.
mature whether the mother age under 35 (younger mom) or 35+ (mature mom)
weeks length of pregnancy in weeks.
premie whether the birth was classified as premature (premie, if weeks <37) or full-term (if 37 weeks or more).
visits number of hospital visits during pregnancy.
marital whether mother is married or not married at birth.
gained weight gained by mother during pregnancy in pounds.
weight weight of the baby at birth in pounds.
lowbirthweight whether baby was classified as low birthweight (low, weight < 5.5066, or not low, if weight \(\ge 5.5066\)).
gender gender of the baby, female or male.
habit status of the mother as a nonsmoker or a smoker.
whitemom whether mom is white or not white.
  1. What are the cases in this data set? How many cases are there in our sample?

The str (structure) command can show us the list of variables in the data, the variable types, and the first few variable values.

str(nc)

As you review the variable summaries, consider which variables are categorical and which are numerical.

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.

  1. Make a side-by-side boxplot of habit and weight. What does the plot highlight about the relationship between these two variables?

The box plots show how the medians of the two distributions compare, but we can also compare the means of the distributions using the aggregate() function to find the mean of the weight variable by mom’s smoking habit.

aggregate(weight ~ habit, data=nc, mean)

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

Inference

  1. Check if the conditions necessary for inference are satisfied. You can obtain the sample sizes of the two groups from the command xtabs(weight ~ habit, data=nc).

  2. Write the hypotheses for testing if the average weights of babies born to smoking and non-smoking mothers are different.

Now, let’s conduct that hypothesis test.

m = aggregate(weight ~ habit, data=nc, mean)
mean.ns = m$weight[1]
mean.s = m$weight[2]

s = aggregate(weight ~ habit, data=nc, sd)
sd.ns = s$weight[1]
sd.s = s$weight[2]

n = xtabs(~habit, data=nc)
n.ns = n[1]
n.s = n[2]

d = mean.ns - mean.s
se = sqrt((sd.ns^2 / n.ns) + (sd.s^2 / n.s))
t = (d - 0) / se

2 * pt(-abs(t), df = min(n.ns-1, n.s-1))

Let’s pause for a moment to go through this code.

First, we compute summary statistics for weight broken down by habit. Those summary statistics include the number of observations (n), the group means (mean), and the group standard deviations (sd).

Then, we calculate our point estimate, d, which is the difference of the mean weights. We compute the standard error, se, and then our t-statistic, t. Finally, we use the pt function to compute the p-value of the t-statistics. Using the simple formula, the degrees of freedom are \(\min(n_s-1, n_{ns}-1)\).

  1. Construct a confidence interval for the difference between the weights of babies born to smoking and non-smoking mothers.

R has a build-in function t.test that can perform the two-sample t-test and the confidence interval above, though it use the more accurate software formula to calculate the degrees of freedom.

t.test(weight ~ habit, data=nc)

On your own

This is a product of OpenIntro that is released under a Creative Commons Attribution-ShareAlike 3.0 Unported. This lab was adapted for OpenIntro by Mine Çetinkaya-Rundel from a lab written by the faculty and TAs of UCLA Statistics.