---
title: "Stat 140 HW#8"
author: "YOUR NAME GOES HERE"
date: "December 4, 2017"
output:
  html_document:
    fig_height: 3
    fig_width: 5
  pdf_document:
    fig_height: 2.7
    fig_width: 6
  word_document:
    fig_height: 3
    fig_width: 5
---


```{r include=FALSE}
# Don't delete this chunk if you are using the mosaic package
# This loads the mosaic and dplyr packages
require(mosaic); require(readr); require(tidyr)

# This changes the default colors in lattice plots.
trellis.par.set(theme=theme.mosaic())  

# knitr settings to control how R chunks work.
require(knitr)
options(digits=5)
opts_chunk$set(
  tidy=FALSE,     # display code as typed
  size="small"    # slightly smaller font for code
)
```

This homework is due at the start of class on Monday, December 4th.

# PRACTICE PROBLEMS (not to be turned in):

SDM4 22.31, 22.33, 22.35, 22.51, 22.53, 22.55, 22.57, 22.59, 22.75

SDM4 23.11, 23.13, 23.15, 23.17, 23.37

# PROBLEMS TO TURN IN:

## SDM4 22.30 Carpal Tunnel, modified

The painful wrist condition called carpal tunnel syndrome can be trated with surgery or less invasive write splints.  Recently, Time magazine reported on a study of 176 patients.  Among the 88 who had surgery, 70 showed improvement after three months.  Among the 88 who used wrist splints, only 42 improved.

### (a) Check the conditions for constructing a confidence interval and conducting a hypothesis about the difference in rate of improvement for surgery relative to wrist splints.

SOLUTION:



### b) Create a 95% confidence interval for the difference in rates of improvement between these two treatments.  Interpret your interval in context.  As part of your interpretation, address what it means to be 95% confident.

SOLUTION:

```{r}
# use the prop.test() function

```



### c) Conduct a hypothesis test at the $\alpha = 0.05$ level.  Write down the null and alternative hypotheses.  Discuss your conclusions in context.  Use the R output from part b) above.

SOLUTION:




## SDM4 22.66 (Egyptians) -- PARTS (a) -- (c) ONLY; I have modified (c) to have you do an explicit hypothesis test

Some archaeologists theorize that ancient Egyptians interbred with several different immigrant populations over thousands of years.  To see if there is any indication of changes in body structure that might have resulted, they measured 30 skulls of male Egyptians dated from 4000 B.C.E. and 30 others dated from 200 B.C.E.  (Source: A Thomson and R. Randall-Maciver, Ancient Races of the Thebaid, Oxford: Oxford University Press, 1905)

```{r}
Egyptians <- read_csv("https://mhc-stat140-2017.github.io/data/sdm4/Egyptians.csv")
names(Egyptians) <- c("skulls_200bce", "skulls_4000bce")
head(Egyptians)
```

### a) Check assumptions for inference

SOLUTION:

```{r}
# Your code goes here

```


### b) Create a 95% confidence interval for the difference in mean skull breadth between these two eras.  Interpret your interval in context.

SOLUTION:

```{r}
# use the t.test() function

```



### c) Conduct a hypothesis test at the $\alpha = 0.05$ level.  Write down the null and alternative hypotheses.  Discuss your conclusions in context.  Use the R output from part b) above.

SOLUTION:



## SDM4 23.3 (Which method II?)

Which of the following scenarios should be analyzed as paired data?

a) Spouses are asked about the number of hours of sleep they get each night.  We want to see if husbands get more sleep than wives.

SOLUTION:



b) 50 insomnia patients are given a placebo and 50 are given a mild sedative.  Which subjects sleep more hours?

SOLUTION:



c) A group of college freshmen and a group of sophomores are asked about the quality of the university cafeteria.  Do students' opinions change during their time at school?

SOLUTION:



## Olympic Swim Suits

In the 2000 Olympics, was the use of a new wetsuit design responsible for an observed increase in swim velocities? In a study designed to investigate this question, twelve competitive swimmers swam 1500 meters at maximal speed, once wearing a wetsuit and once wearing a regular swimsuit (De Lucas et. al, The effects of wetsuits on physiological and biomechanical indices during swimming. \textit{Journal of Science and Medicine in Sport,} 2000; 3(1): 1-8}).  The order of wetsuit versus swimsuit was randomized for each of the 12 swimmers. The R chunk below reads in the data, with the average velocity recorded for each swimmer, measured in meters per second (m/s).

```{r}
swim_times <- read_csv("https://mhc-stat140-2017.github.io/data/misc/olympic_wet_suits/olympic_wet_suits.csv") %>%
  mutate(
    velocity_difference = wet_suit_velocity - swim_suit_velocity
  )
head(swim_times)
```

### a) Check assumptions for inference

SOLUTION:

```{r}
# Your code goes here

```


### b) Create a 95% confidence interval for the difference in mean swim times with the wet suit and with a regular swim suit.  Interpret your interval in context.

SOLUTION:

```{r}
# use the t.test() function

```



### c) Conduct a hypothesis test at the $\alpha = 0.05$ level.  Write down the null and alternative hypotheses.  Discuss your conclusions in context.  Use the R output from part b) above.

SOLUTION:
