Question: Load the kobe data frame, which contains all the shots from Kobe Bryant of the Los Angeles Lakers against the Orlando Magic in the 2009
"Load the kobe data frame, which contains all the shots from Kobe Bryant of the Los Angeles Lakers against the Orlando Magic in the 2009 National Basketball Association (NBA) finals.
download.file("http://www.openintro.org/stat/data/kobe.RData", destfile = "kobe.RData")
load("kobe.RData")
This will also load a new function, calc_streak that you will need for the assignment below.
Now write code to answer the following questions. Make sure the script that you turn in includes the code that you write, the output that you get from that code (in a comment), and a sentence or more answering the question if there was one (also in a comment).
- The basket column has the value H every time Kobe made (hit) a shot and the value M every time he missed a shot. make a table containing Kobe's probability distribution of making or missing a shot, and assign it to the variable kobe.basket.prob.
- Write code to extract just the probability of H from kobe.basket.prob.
- Print out the first 13 of Kobe's shots. Apply the calc_streak function to these first 13 shots. Describe how this function is calculating "streaks".
- Use a barplot to graph the distribution of Kobe's streaks across the entire data. (Hint: there should be fewer than 10 bars.)
- We're now going to simulate a player that has the same chance of hitting or missing a shot as Kobe, but has no notion of a streak (i.e., each shot is independent of every other shot). Use the sample function to make a sample of shot outcomes, where the size of the sample is the same as the number of Kobe's shots and the probability of H and M is the same as Kobe's. Use this sample for the next 3 questions.
- Calculate the sample's probability distribution of making or missing a shot across the entire data. Does it differ from Kobe's probability distribution in step 1? Should it? Why or why not?
- Apply the calc_streak function to the sample, and use a barplot to graph the distribution of the sample's streaks. How does it compare to the plot of Kobe's streaks in step 4? (Make sure that your y-axes are the same scale.)
- Calculate the probability distribution over streak lengths for both Kobe and your sample. How similar or different are they?
- Use the replicate function to run the following procedure 100 times:
- make a sample as in step 5.
- Apply the calc_streak function to the sample.
- Calculate the probability distribution over the sample's streak lengths.
- Extract just the entry of the probability distribution that corresponds to the streak of length 0.
Then get a summary of all the collected probabilities of length-0 streaks. Is Kobe's probability of a length-0 streak (which you calculated in step 8) typical? Why or why not?
10. Repeat the process from 9, but now look at length-3 streaks. Is Kobe's probability of a length-3 streak (which you calculated in step 8) typical? In general, does Kobe seem to be more, less, or equally likely to get a streak of successful shots as compared to a simulated player whose shots are all independent from each other?"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
