---
title: "Challenge Questions"
output:
  pdf_document: default
  html_notebook: default
---




$\\$



The goal of these questions is see if you can apply what you learned over the course of the semester to answer questions.  Please talk with other members of the class and let's see if we can come up with some convincing answers!




<!-- This R chunk sets some parameters that will be used in the rest of the document. -->
```{r message=FALSE, warning=FALSE, tidy=TRUE, echo = FALSE}

 library(knitr)
 
 # makes sure the code is wrapped to fit when it creats a pdf
 opts_chunk$set(tidy.opts=list(width.cutoff=60)) 
 
 set.seed(1)  # set the random number generator to always give the same sequence of random numbers

 require("Lahman") # you need to run this every time you use the Lahman database
 require("dplyr")  # use the dplyr functions to manipulate data 

 
 
```




$\\$




**Question 1**: Baseball teams need to fly a lot during the season (April through September). Understanding whether a flight is going to be delayed could potentially help a team plan better for games on the road. In this exercise we will examine whether flights leaving from Houston (where the Astros play), are delayed longer (on average) when flying to Boston (to play the Red Sox) compared to when they fly to Oakland (to play the Athletics). In particular, see if you can *convincingly*  answer the question of whether the mean delay to Boston is longer than the mean delay to Oakland using plots and hypothesis tests. 

A list of flight information is given below in a data frame called the.flights. Information about departing and destination cities are in the variables Origin, and Dest respectively, while information about how delayed a flight was to arrive is in the variable ArrDelay. Some functions that you might find useful for examining this data are: filter(), boxplot(), t.test(), and sample().




```{r message=FALSE, warning=FALSE, tidy=TRUE} 

# get the flight delay data 
 
require('hflights')

the.flights <- hflights 
 




```


*Answers*


$\\$






**Challenge Question 2**

Part a: In this question we will examine the most common name in baseball. All the first names of baseball players are in the variable   Master$nameFirst. See if you can figure out what the most common first name in baseball is. Then plot how many people with the most common first name were born in each year, and plot how many people were born with this name as a function of the year they were born. Functions you might find useful are:  table(), which.max() and filter().

Part b: The names of all babies born in the United States are loaded before in a variable called baby.names. The variable baby.names$prop contains the proportion of babies born with a given name. Plot the proportion of babies with the most common baseball name as a function of year. Does this look similar to the proportion of baseball players with this name? 





```{r message=FALSE, warning=FALSE, tidy=TRUE}


# Get the most common first name in baseball and the number of people born each year with this name as a function of the year




# Get the names of all babies born in the US and plot the most common baseball name as a function of the year

require('babynames')
baby.names <- babynames





```





