---
title: "Midterm 2 Template"
author: "Insert Name"
date: "Math 141, Spring 2021"
output:
  pdf_document
urlcolor: blue
---

```{r setup, include=FALSE}
# Do not modify this chunk.
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(knitr)
library(moderndive)
library(infer)
library(ISLR)
library(openintro)
library(Lock5Data)
```





## Instructions

1. Download the Midterm 2 .Rmd Template (this file).

2. Work through the exam questions in the .pdf file on [Gradescope](https://www.gradescope.com/courses/227442), recording your answers in the .Rmd template, and submit the document as a knitted .pdf file with your answers on Gradescope. Only what appears in the .pdf file will be graded, so if what you see in the .pdf doesn't reflect what you intend for the answer, modify your .rmd file so the .pdf reflects your answer.

3. You may take up to 150 minutes to complete this exam. You may start the exam at any time, but you must cease working and submit your .pdf file 150 minutes after you begin. You will be unable to submit the assignment to gradescope after this time has elapsed. If you have academic accommodations permitting additional time on the exam, and we have discussed these accommodations, I have incorporated the additional time in your assignment.

4. You may reference your Lab Assignments (both the versions you submitted and the comments you received), your course notes, textbooks (both ModernDive and OpenIntro), lecture slides, and lecture videos. 

5. You may also reference any built-in help functions in R (for example, you may look at the results of typing `?ggplot` into the console or the cheat sheets on the help menu). 

6. You **MAY NOT** reference any other physical or online sources, repost any questions from this exam, or receive help on this assignment from others in any way. Failure to abide by this policy is an Honor Code violation.

7. If you have technical questions, send them to Nate and Tom as a joint direct message on Slack. For equity reasons, we will not answer conceptual or clarifying questions. Since we maybe unable to answer your question during the time frame you are taking the exam, document the issue on the exam and then move on to the next problem.

8. Knit your document early and often! If a code chunk is preventing you from knitting the document and you are unable to resolve the problem, replace `{r}` at the top of the code chunk with `{r eval = F, echo = T}`. The code will not run, but will be printed in your .pdf which can possibly earn some partial credit.

9. For each problem, put your solution between the bars of red stars.


## Data

This exam will make use of three data sets. For each set, perform some preliminary data exploration to understand the distribution of each variable, along with the relationships among the variables. 

To facilitate exploration, you may want to make a copy of this .Rmd file called `Midterm2_Scratchwork` where you can make changes to the data without impacting the version of this template you will use to submit your exam.



### Data Set 1: College Stats 


**If you get an error message when attempting to run the code chunk that loads the `College` data, please copy/paste the following code into the console in the lower left pane of RStudio. You only need to do this once.**

```{r eval = F, echo = T}
install.packages("ISLR")
```


The `College` data set from the `ISLR` package contains statistics for a large number of US Colleges from the 1995 issue of US News and World Report, originally collated for use in the ASA Statistical Graphics Section's
1995 Data Analysis Exposition. The data can be loaded with the following code:

```{r message = F, warning  = F}
library(ISLR)
data("College")
```

The data frame contains 777 observation on 18 variables. Run the following code to view the codebook explaining each variable in the data. *Note that `eval = F` is used so the help file does not produce an error when knitting the document.*

```{r eval = F}
?College
```


### Data Set 2: Friday the 13th

The `friday` data set from the `openintro` package contains traffic and shopping patterns, and accident frequencies for Fridays the 6th and Fridays the 13th between October 1989 and November 1992, in Southeast England. It was originally collected by Scanlon, T.J., Luben, R.N., Scanlon, F.L., Singleton, N. with assistance from the British Department of Transport. The data can be loaded with the following code:

```{r message = F, warning  = F}
library(openintro)
data("friday")
```

The data frame contains 61 observation on 6 variables. Run the following code to view the codebook explaining each variable in the data. *Note that `eval = F` is used so the help file does not produce an error when knitting the document.*

```{r eval = F}
?friday
```


### Data Set 3: StockChanges

The S&P 500 is a stock market index that records the stock performance for 500 large companies listed in the US stock exchange, including Apple, Microsoft, Amazon, and Facebook. The `StockChanges` data set from the `Lock5Data` package contains stock price changes for a random sample of 50 stocks from the S&P 500 during the period of August 2 - 6, 2010. The data can be loaded with the following code:

```{r message = F, warning  = F}
library(Lock5Data)
data("StockChanges")
```

The data frame contains 50 observation on the variable `SPChange`, which measures the change in stock price (in dollars). It will be helpful to quickly determine whether a given stock increased or decreased in price over the period of August 2 - 6. Run the following code to create a variable `increased` indicating whether the stock increased in price.

```{r}
library(dplyr)
StockChanges <- StockChanges %>% mutate(
  increased = ifelse(
    SPChange > 0, 
    "yes",
    "no"
  )
)
```







## Exam

Write your answers to questions in the Midterm 2 .pdf between the bars of red stars below. You may copy and paste the questions from the .pdf file into the space below (but you do not need to).


### Problem 1




*************************************************************





*************************************************************





### Problem 2




*************************************************************





*************************************************************







### Problem 3




*************************************************************





*************************************************************








### Problem 4




*************************************************************





*************************************************************







### Problem 5




*************************************************************





*************************************************************






### Problem 6




*************************************************************





*************************************************************