Lab 7
Tobias Johnson
3/22/2018
Getting Started
A few quick reminders:
The console lets you try commands and see the results right away, but nothing you do there is saved.
To create the file that you’ll eventually hand in, go to File -> New File -> R Script. Save the file as
lab7.R
or something like that. In this file, put your answers like this:# Exercise 1 mean(dataset$left.bicep.thickness) mean(dataset$right.bicep.thickness) # On average, people's right biceps are thicker than their left biceps # Exercise 2
To compile your R file, press Ctrl-Shift-K, or click on the little notebook icon in the toolbar. When it asks for the report output format, choose html.
If you load a dataset in the console, this doesn’t make it available in your R file. If you load a dataset in your R file, this doesn’t make it available in the console.
To run a line of code from your R file in the console without having to type it in again, put your cursor on the line and press Ctrl-Enter.
You can look up a command in help by putting the cursor on it and pressing F1. Or, in the console, enter in a question mark followed by the name of the command, like
?mean
.
Goals
Today, we’ll get practice with tests of significance. The test we’ll use is a one-sample z-test.
Exercise 1
We’ll use the same dataset as last week, available at http://www.math.csi.cuny.edu/~maher/teaching/2019/spring/stats/labs/nc.csv
Recall that each observation represents one birth, and that the variables are:
variable | definition |
---|---|
fage |
age of father in years |
mage |
age of mother in years |
mature |
either "mature mom" or "younger mom" , depending on the age of the mother |
weeks |
length of pregnancy in weeks |
premie |
either "full term" or "premie" , depending on whether the baby was born prematurely |
visits |
number of hospital visits by the mother during pregnancy |
marital |
either "married" or "not married" , depending on status of parents |
gained |
weight gained by mother during pregnancy in pounds |
weight |
birthweight of baby in pounds |
lowbirthweight |
either "low" or "not low" depending on whether baby was categorized as having a low birth weight |
gender |
gender of baby, either "male" or "female" |
habit |
either "nonsmoker" or "smoker" depending on if mother smokes cigarettes |
whitemom |
either "white" or "nonwhite" , referring to race of the mother |
Task. Load the dataset into an object called nc
.
Exercise 2
The question we’ll investigate today: It’s said that the mean birthweight for full-term babies is 7.6 pounds. (full-term means not born prematurely.) We’d like to know if the dataset provides evidence that the mean birthweight for full-term babies in North Carolina is different from this number.
Task. In words, state null and alternative hypotheses to investigate this question.
Exercise 3
Task. Make a new dataset called nc.ft
that consists only of the full-term babies, coded by the variable premie
.
Hint: Remember the subset
command! See Exercise 4 in Lab 5, for example.
Exercise 4
Task. Find the mean \(\bar{x}\) and standard deviation \(s\) for the birthweight of the full-term babies in your sample.
Exercise 5
Task. Assuming that the population standard deviation \(\sigma\) is the same as the sample standard deviation \(s\), compute the standard deviation of the sampling distribution of \(\bar{x}\).
Exercise 6
In this question, assume that the sampling distribution of \(\bar{x}\) is approximately normal.
Task. Find the p-value for your test. Recall: Assume that the null hypothesis is true. Then how likely is it to observe \(\bar{x}\) as strongly in favor of the alternative hypothesis as you did?
Exercise 7
What is your conclusion? Do you reject the null hypothesis in favor of the alternative hypothesis? Or do you fail to reject the null hypothesis? Use a significance level of .05.
If you have extra time…
Exercise 8
Task. Make a boxplot showing the distributions of weights for the full-term babies of each sex. Just from the diagram, do you think that baby boys and girls have different birthweights on average?
Exercise 9
Task. Construct 95% confidence intervals for the mean birthweight of full-term boys and the mean birthweight of full-term girls. Assume that the sampling distributions of the means are approximately normal and that the population standard deviations are equal to the sample standard deviations. (In chapter 7, we’ll finally learn how to handle this properly.)
Exercise 10
Task. Investigate whether birthweights of full-term babies are normally distributed.