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.
Load the nc
data set into our workspace.
= read.csv("https://www.openintro.org/stat/data/csv/ncbirths.csv") nc
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 . |
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.
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.
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)
.
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.
= aggregate(weight ~ habit, data=nc, mean)
m = m$weight[1]
mean.ns = m$weight[2]
mean.s
= aggregate(weight ~ habit, data=nc, sd)
s = s$weight[1]
sd.ns = s$weight[2]
sd.s
= xtabs(~habit, data=nc)
n = n[1]
n.ns = n[2]
n.s
= mean.ns - mean.s
d = sqrt((sd.ns^2 / n.ns) + (sd.s^2 / n.s))
se = (d - 0) / se
t
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)\).
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)
Calculate a 95% confidence interval for the average length of
pregnancies (weeks
) and interpret it in context.
Calculate a new confidence interval for the same parameter at the 90% confidence level.
Conduct a hypothesis test evaluating whether the average weight gained by younger mothers is different than the average weight gained by mature mothers.
Determine the age cutoff for younger and mature mothers. Use a method of your choice, and explain how your method works.
Pick a pair of numerical and categorical variables and come up with a research question evaluating the relationship between these variables. Formulate the question in a way that it can be answered using a hypothesis test and/or a confidence interval. Answer your question by performing the hypothesis test or calculating the confidence interval, and also provide an explanation in plain language.
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.