Before you begin the homework assignment, take some time to familiarize yourself with the aov, prop.test, and chisq.test functions in R, as we will be using them extensively on this homework. A brief tutorial is given in the first part of the homework below.

Creating R Markdown files

There is no template for this homework. Instead, create your own R Markdown file in R by going to File > New File > R Markdown. In the spaces provided, give the title (HW 05) and author (your name), and select “HTML document”. You should see a new file appear that has the following header:

---
title: "HW 06"
author: "Yue Jiang"
date: "10/8/2020"
output: html_document
---

There’s also some some example Markdown code that appears under this header. You may safely delete it. Use previous templates as guides for creating your own Markdown document.

Data

We’ll be revisiting the licorice example presented in lecture and HW 05. As a review, postoperative sore throat is an annoying, but painful complication of intubation after surgery, particularly with wider gauge double-lumen tubes. Reutzler et al. (2013) performed an experimental study among patients having elective surgery who required intubation with a double-lumen tube. Prior to anesthesia, patients were randomly assigned to gargle either a licorice-based solution or sugar water (as placebo). Sore throat was evaluated 30 minutes, 90 minutes, and 4 hours after conclusion of the surgery (from 0 to 10).

We’ll assume that we can treat pain score as a continuous numeric variable.

The data are available with the following code:

library(tidyverse)
licorice <- read.csv("https://www2.stat.duke.edu/courses/Fall20/sta102/hw/data/licorice.csv")

Some relevant variables of interest are:

R chunk options

To suppress printed messages and warnings in your R Markdown document, you may use the options message = F and warning = F in your R chunk. That is, we may start the R chunk with ```{r chunk-name, message = F, warning = F}.

ANOVA

To conduct an ANOVA in R, we will take a summary of the aov function to create the ANOVA table. The general syntax is summary(aov(outcome_var ~ grouping_var, data = dataset)), where outcome_var is the numerical variable you’re interested in calculating means of (e.g., the pulse rate in the experiment talked about in clasS) and grouping_var is the grouping variable (e.g., pet vs. friend vs. neither).

Example: Suppose you’re interested in testing whether there is a difference in mean BMI between patients of the three ASA categories:

summary(aov(preOp_calcBMI ~ preOp_asa, data = licorice))
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## preOp_asa     2    262  131.21   7.595 0.000638 ***
## Residuals   232   4008   17.28                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Note that the ANOVA table provides all output talked about in the lecture slides. The between-group variance component is given in the top line and the within-group variance component is given in the bottom line.

One-sample tests of proportion

Suppose you are interested in testing a single proportion. You may use the prop.test() function to do so, and it contains the following arguments:

Example: Suppose in our data we observe 63 “successes” out of 81, and wante to test whether this proportion is greater than the null hypothesized proportion \(p_0 = 0.7\) at the \(\alpha = 0.05\) significance level:

prop.test(x = 63, n = 81, p = 0.7, alternative = "greater", conf.level = 0.95)
## 
##  1-sample proportions test with continuity correction
## 
## data:  63 out of 81, null probability 0.7
## X-squared = 1.9777, df = 1, p-value = 0.07982
## alternative hypothesis: true p is greater than 0.7
## 95 percent confidence interval:
##  0.6868443 1.0000000
## sample estimates:
##         p 
## 0.7777778

Note that the output displays a \(\chi^2\) statistic and degrees of freedom. This is similar to the test using the normal distribution covered in the lecture slides. You may safely use R to evaluate any hypothesis tests for proportions, and thus may use this \(\chi^2\) statistic for a test of proportions. The output also includes the p-value, the alternative hypothesis tested, a confidence interval, and the data itself.

Chi-square test

Chi-square tests are performed in R by inputing a table into the chisq.test function. To create a table, use the table function. For instance, to create a table that counts the values of a single variable, you may use table(dataset$var1). To create a two-way contingency table, you may use table(dataset$var1, dataset$var2).

Example: Suppose you want to create a two-way contingency table comparing ASA status with the gender of the patients in the licorice dataset:

table(licorice$preOp_asa, licorice$preOp_gender)
##                   
##                     0  1
##   healthy          26 15
##   mild_disease     80 54
##   systemic_disease 36 24

To conduct a chi-square test, simply wrap the table in the chisq.test function.

Example: Is there an association between ASA and gender among patients receiving surgeries requiring intubation?

chisq.test(table(licorice$preOp_asa, licorice$preOp_gender))
## 
##  Pearson's Chi-squared test
## 
## data:  table(licorice$preOp_asa, licorice$preOp_gender)
## X-squared = 0.18711, df = 2, p-value = 0.9107

Note that the output provides the \(\chi^2\) statistic, the degrees of freedom, and the p-value.

Exercises

In questions 1 - 5, use the licorice dataset as referred to in the brief tutorial above and in class. You may assume that the pain scores are continuous numeric variables for the purposes of this assignment.

When conducting a hypothesis test, you must always formally specify the significance level, the hypotheses of interest, the reference distribution of the test statistic under the null hypothesis, the test statistic itself, the p-value, your decision, and a conclusion in context of the research problem.

  1. 10 points Comprehensively test whether there was an equal proportion of men vs. women in the study.
  2. 20 points Create a binary variable that corresponds to whether the patient experiences any throat pain 30 minutes after surgery (i.e., any non-zero pain score would be indicative of pain). Comprehensively evaluate whether there is an association between whether the patient experiences throat pain 30 minutes after surgery and the ASA classification of the patient prior to surgery. As part of your answer, evaluate the assumptions for your chosen test. Regardless of whether the assumptions are satisfied, carry out your test.
  3. 20 points Comprehensively evaluate whether there is an association of whether the patient experiences throat pain 30 minutes after surgery and what type of treatment the patient received. As part of your answer, evaluate the assumptions for your chosen test. Regardless of whether the assumptions are satisfied, carry out your test.
  4. 20 points Comprehensively evaluate whether the mean throat pain score 30 minutes after surgery varies by ASA classification. As part of your answer, evaluate the assumptions for your chosen test. If you find a significant difference, you do not need to perform any step-down tests.
  5. 10 points Regardless of your answer in Exercise 4, suppose you found evidence of differential mean pain score by ASA classification and wanted to perform a step-down test. comprehensively describe how you would carry out such tests. In your answer, include the specific type of tests used, what the null and alternative hypotheses would be (only listing one set is fine), and how you would determine whether you would reject or fail to reject these step-down hypotheses.
  6. 10 points In your own words, explain why it “makes sense” to evaluate equality of means across groups by examining different types of variances.
  7. 10 points In your own words, explain the intuition and motivation behind the chi-square test to somebody who has never seen it before (but who is familiar with the philosophy of hypothesis testing).

Acknowledgements

Today’s dataset was made available by the Lerner Research Institute and Dr. Amy S. Nowacki of the Cleveland Clinic. These data are representative of a study by Ruetzler et al. (2013).