Lab 11

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 lab8.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.

Exercise 1

This lab uses a dataset from a study on depression and coffee consumption in women (see exercise 6.48 from OpenIntro Statistics). You can download it from http://www.math.csi.cuny.edu/~maher/teaching/2019/spring/stats/labs/coffee.csv

Task. Download the dataset and load it into an object called study.

Exercise 2

## Warning in file(file, "rt"): "internal" method cannot handle https
## redirection to: 'https://www.math.csi.cuny.edu/~maher/teaching/2019/spring/
## stats/labs/coffee.csv'
## Warning in file(file, "rt"): "internal" method failed, so trying "libcurl"

Here’s a quick look at the dataset:

str(study)
## 'data.frame':    50739 obs. of  2 variables:
##  $ depression: Factor w/ 2 levels "n","y": 1 1 1 1 1 1 1 1 1 1 ...
##  $ coffee    : Factor w/ 5 levels "<=1 cup/week",..: 3 5 3 5 3 4 3 1 3 3 ...
study[1:100,]
##     depression        coffee
## 1            n     1 cup/day
## 2            n 2-6 cups/week
## 3            n     1 cup/day
## 4            n 2-6 cups/week
## 5            n     1 cup/day
## 6            n  2-3 cups/day
## 7            n     1 cup/day
## 8            n  <=1 cup/week
## 9            n     1 cup/day
## 10           n     1 cup/day
## 11           n  2-3 cups/day
## 12           n     1 cup/day
## 13           n  <=1 cup/week
## 14           n     1 cup/day
## 15           n     1 cup/day
## 16           n     1 cup/day
## 17           n     1 cup/day
## 18           n     1 cup/day
## 19           n  2-3 cups/day
## 20           n 2-6 cups/week
## 21           n  >=4 cups/day
## 22           n  2-3 cups/day
## 23           n  2-3 cups/day
## 24           n  2-3 cups/day
## 25           n  2-3 cups/day
## 26           n  <=1 cup/week
## 27           n 2-6 cups/week
## 28           n 2-6 cups/week
## 29           n     1 cup/day
## 30           n  2-3 cups/day
## 31           n  <=1 cup/week
## 32           n     1 cup/day
## 33           n  2-3 cups/day
## 34           n  2-3 cups/day
## 35           n  2-3 cups/day
## 36           n  2-3 cups/day
## 37           n  <=1 cup/week
## 38           n  2-3 cups/day
## 39           n  >=4 cups/day
## 40           n     1 cup/day
## 41           n     1 cup/day
## 42           n     1 cup/day
## 43           n     1 cup/day
## 44           n     1 cup/day
## 45           n     1 cup/day
## 46           n  2-3 cups/day
## 47           n     1 cup/day
## 48           n     1 cup/day
## 49           n  <=1 cup/week
## 50           n     1 cup/day
## 51           n  2-3 cups/day
## 52           n     1 cup/day
## 53           n  <=1 cup/week
## 54           n     1 cup/day
## 55           n     1 cup/day
## 56           n  <=1 cup/week
## 57           n     1 cup/day
## 58           n 2-6 cups/week
## 59           n  <=1 cup/week
## 60           n  2-3 cups/day
## 61           n 2-6 cups/week
## 62           n     1 cup/day
## 63           n  <=1 cup/week
## 64           n  2-3 cups/day
## 65           n  >=4 cups/day
## 66           n  <=1 cup/week
## 67           n  2-3 cups/day
## 68           n 2-6 cups/week
## 69           n     1 cup/day
## 70           n     1 cup/day
## 71           n  <=1 cup/week
## 72           n  2-3 cups/day
## 73           n     1 cup/day
## 74           n     1 cup/day
## 75           n     1 cup/day
## 76           n  <=1 cup/week
## 77           n 2-6 cups/week
## 78           n     1 cup/day
## 79           n 2-6 cups/week
## 80           n  2-3 cups/day
## 81           n     1 cup/day
## 82           n  <=1 cup/week
## 83           n  2-3 cups/day
## 84           n 2-6 cups/week
## 85           n 2-6 cups/week
## 86           n  2-3 cups/day
## 87           n  2-3 cups/day
## 88           n  <=1 cup/week
## 89           n  <=1 cup/week
## 90           n     1 cup/day
## 91           n 2-6 cups/week
## 92           n  2-3 cups/day
## 93           n  >=4 cups/day
## 94           n     1 cup/day
## 95           n  2-3 cups/day
## 96           y  <=1 cup/week
## 97           n  2-3 cups/day
## 98           n  <=1 cup/week
## 99           n  <=1 cup/week
## 100          n  <=1 cup/week

The study started with 50,739 women with no symptoms of depression in 1996. The researchers then collected information on coffee consumption and the development of depression over the next ten years. The variable depression codes whether the women experienced clinical depression, with "n" meaning no and "y" meaning yes. The variable coffee gives each woman’s average intake of coffee.

Your assignment is to try to determine if coffee drinking has any association with depression, at 5% significance level.

Task. What test will you use to answer this question? What are your hypotheses?

Exercise 3

Task. Make a two-way table giving the counts of people in each coffee-drinking category who have and have not experienced depression. Store it as an object and print it out.

Hint: You’ll want to use the table command.

Exercise 4

Task. Determine if the conditions for your test are satisfied.

Exercise 5

Task. Carry out the test. What is your conclusion?

Exercise 6

Task. Answer these questions: Is this an experiment or an observational study? Can you make any conclusions about causality?

Exercise 7

Task. Which level of coffee drinking is associated with the lowest level of depression?

To answer this question, you’ll want to count up the number of people experiencing depression in each coffee drinking category and divide by the total number of people in the category. Hint: You’ve probably already used the table command to do some of the counting for you.

Exercise 8

Task. Tell me any speculations you have about the reason for any association you find. There are no right or wrong answers here: I’m just curious what you think.