#Load the data
bball <- read.csv("https://raw.githubusercontent.com/marctrussler/IIS-Data/main/CollegeBasketball.csv")Problem Set 1
Problem Set Due Wednesday September 25th at 7pm on Canvas.
You will hand in a .Rmd file and a knitted html output.
I have provided the raw RMD of this problem set you can use as a template for answering.
Question 1: Probability & Counting
(a) In a game of poker each player is dealt 5 cards from a 52 card deck. How many different 5 card poker hands can be generated from a 52 card deck? (Hint: Is this a permutation or a combination?).
(b) There are 4 suits in a card deck, each consisting of 13 cards. A “flush” is a poker hand where all 5 cards are of the same suit. Calculate the probability of being dealt a flush. (Hint: You first need to count all the ways you can make a 5 card hand using only cards from one suit.)
(c) Simulate the answer to question (b) using R. Run a loop 100000 times that draws 5 cards from a deck of 52, where there are 4 suits with 13 cards each. Note, that we don’t care which cards are which within a suit. We just need 13 hearts, 13 diamonds, 13 clubs, 13 spades. How often are you dealt a flush? (Hint: to see if all the cards in my hand were of the same suit I started with the unique() command.)
(d) A manufacturer of code-based locks comes to you worried that the codes on his lock are too easy to guess. He tells you that his locks have a dial with 10 numbers and the codes are 3 digits long. Like most locks, the numbers in the code cannot repeat and the order of the numbers matters. Calculate the probability of guessing this code using both math and simulation. For the simulation, run the loop 1 million times.
(e) To help this manufacturer we want to determine if it’s more effective to manufacture a bigger dial or to require the user to use a longer code. Using R to simulate each possibility 1 million times, make two graphs. For the first graph, determine the probability of guessing a code with dial sizes from 10 to 30 numbers and a 3 digit code. For the second graph, determine the probability of guessing a code with a dial size of 10, but code lengths from 3-10 numbers long. What do you find?
Question 2: Conditional Probability in Data
This problem is going to have you examine some data on the outcomes of college basketball games. I have a theory for why in certain games that underdogs (i.e., the team that is seen as less likely to win a game before the game starts) will perform better than people expect when the score is higher than people expect, and favorites (i.e., the team that is seen as more likely to win a game before the game starts) will perform better than people expect when the score is lower than people expect. In other words, I believe that upsets are more likely in higher scoring games. To test this theory, I tracked the outcomes of 241 games between 1/22/2019-3/29/2019 in which I assessed my theory would apply. Data about these games are contained in ‘’CollegeBasketball.csv’’. We are going to examine these data to see whether the empirical evidence is consistent with my theory.
You can load the data via:
Here is a description of the relevant variables contained in “CollegeBasketball.csv”:
PredictedDifferenceare gamblers’ expectations for how many more points the favorite will score compared to the underdog. Because the favorite is expected to win (they are the favorite!) this number is always positive.ActualDifferenceis how many more points the favorite scored than the underdog in the game, meaning that it is a negative number when the underdog won the game.PredictedPointsare gamblers’ expectations about the total number of points that will be scored in the game.ActualPointsis how many combined points the favorite and the underdog scored.
Answer the following questions using R:
(a) Make a new variable that is equal to ActualDifference minus PredictedDifference. Create a histogram (hist()) that shows the distribution of this variable and briefly describe what it shows.
(b) Let \(W\) represent the event that the favorite won a basketball game by more points than expected, \(E\) represent the event that the favorite won a basketball game by exactly the number of points that were expected, and \(L\) be the event that the favorite won a basketball game by fewer points than expected or lost a basketball game. Using the variable you created in (a), make three new boolean variables indicating whether these events occurred in each game and use these variables to calculate within the sample \(P(W)\), \(P(E)\), and \(P(L)\).
(c) Make a new variable that is equal to ActualPoints minus Predicted Points. Create a histogram that shows the distribution of this variable and briefly describe what you see.
(d) Let \(O\) represent the event that more combined points were scored than expected, \(T\) represent the event that the combined points scored were exactly the number expected, and \(U\) represent the event that fewer combined points were scored than expected. Make new variables indicating whether these events occurred in each game and use these variables to calculate within the sample \(P(O)\), \(P(T)\), and \(P(U)\).
(e) To assess the overall theory that favored teams do worse in high scoring games, use the conditional probability formula discussed in lecture to calculate \(P(W \mid U)\) and \(P(W \mid O)\). (You can also calculate \(P(L \mid U)\) and \(P(L \mid O)\) to further confirm or dismiss the theory, if you want).
(f) In two or three sentences: what is your conclusion about my theory?