2/18/21
## Warning: package 'tidyverse' was built under R version 4.0.3
## Warning: package 'openintro' was built under R version 4.0.3
## Warning: package 'airports' was built under R version 4.0.3
## Warning: package 'cherryblossom' was built under R version 4.0.3
## Warning: package 'usdata' was built under R version 4.0.3
## Warning: package 'wesanderson' was built under R version 4.0.3
## Rows: 133
## Columns: 6
## $ vs <fct> ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ...
## $ game <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ quarter <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3...
## $ time <fct> 9:47, 9:07, 8:11, 7:41, 7:03, 6:01, 4:07, 0:52, 0:00, 6...
## $ description <fct> Kobe Bryant makes 4-foot two point shot, Kobe Bryant mi...
## $ shot <chr> "H", "M", "M", "H", "H", "M", "M", "M", "M", "H", "H", ...
What does a streak length of 1 mean, i.e. how many hits and misses are in a streak of 1? What about a streak length of 0? > This means there is one hit, followed by a miss immediately. A streak of length 0 means there are only consecutive misses.
Describe the distribution of Kobe’s streak lengths from the 2009 NBA finals. What was his typical streak length? How long was his longest streak of baskets? Make sure to include the accompanying plot in your answer. > The data of Kobe’s streaks follows a right-skew distribution. His longest streak of baskets is 4, although he nearly has 40 misses during this game.
# Insert code for Exercise 2 here
#calculating and seeing Kobe's streaks:
kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) + geom_bar()
In your simulation of flipping the unfair coin 100 times, how many flips came up heads? Include the code for sampling the unfair coin in your response. Since the markdown file will run the code, and generate a new sample each time you Knit it, you should also “set a seed” before you sample. Read more about setting a seed below.
82 times heads via unfair coin.
# Insert code for Exercise 3 here
coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
## [1] "tails"
# Fair
set.seed(100)
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 50 50
# Unfair
set.seed(100)
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE,
prob = c(0.2, 0.8))
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails
## 18 82
What change needs to be made to the sample function so that it reflects a shooting percentage of 45%? Make this adjustment, then run a simulation to sample 133 shots. Assign the output of this simulation to a new object called sim_basket.
set.seed(133)
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE, prob = c(.45, .55))
table(sim_basket)
## sim_basket
## H M
## 73 60
Using calc_streak, compute the streak lengths of sim_basket, and save the results in a data frame called sim_streak.
### Code for exercise 6
library(ggplot2)
library(tidyr)
set.seed(133)
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE, prob = c(.45, .55))
table(sim_basket)
## sim_basket
## H M
## 73 60
## length
## 1 0
## 2 2
## 3 0
## 4 2
## 5 2
## 6 2
## 7 0
## 8 0
## 9 0
## 10 1
## 11 0
## 12 4
## 13 2
## 14 0
## 15 2
## 16 0
## 17 0
## 18 2
## 19 1
## 20 1
## 21 3
## 22 0
## 23 0
## 24 1
## 25 5
## 26 2
## 27 0
## 28 6
## 29 2
## 30 0
## 31 0
## 32 0
## 33 0
## 34 5
## 35 1
## 36 4
## 37 0
## 38 1
## 39 2
## 40 0
## 41 1
## 42 1
## 43 3
## 44 1
## 45 1
## 46 1
## 47 0
## 48 0
## 49 1
## 50 2
## 51 3
## 52 0
## 53 0
## 54 1
## 55 1
## 56 2
## 57 1
## 58 0
## 59 1
## 60 0
## 61 0
hist(sim_streak$length, main = "Length of Streaks", xlab = "Common Shots", ylab = "Frequency", breaks = 10)
Describe the distribution of streak lengths. What is the typical streak length for this simulated independent shooter with a 45% shooting percentage? How long is the player’s longest streak of baskets in 133 shots? Make sure to include a plot in your answer. > The streak lengths follow a right skew distribution. > The typical streaks for hits are single shots. After that, doubles are the second common, followed by triples and quadruples tied for third, and sextuplets being the least common with one occurence. The breakdown of streaks are as follows:
singles: 16x doubles: 12x triples: 3x quads: 4x sext.: 1x
If you were to run the simulation of the independent shooter a second time, how would you expect its streak distribution to compare to the distribution from the question above? Exactly the same? Somewhat similar? Totally different? Explain your reasoning. > Although the outcome would indeed be different, the data would be distributed similarly to how it was distributed the first time. This is because the probabilty that the shooter would make the shots remains the same.
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE, prob = c(.45, .55))
table(sim_basket)
## sim_basket
## H M
## 58 75
## length
## 1 0
## 2 3
## 3 0
## 4 0
## 5 0
## 6 1
## 7 0
## 8 0
## 9 1
## 10 2
## 11 0
## 12 0
## 13 0
## 14 0
## 15 2
## 16 1
## 17 5
## 18 0
## 19 4
## 20 0
## 21 0
## 22 0
## 23 0
## 24 2
## 25 0
## 26 1
## 27 0
## 28 1
## 29 0
## 30 2
## 31 0
## 32 1
## 33 0
## 34 0
## 35 0
## 36 0
## 37 0
## 38 0
## 39 1
## 40 1
## 41 1
## 42 1
## 43 0
## 44 1
## 45 0
## 46 3
## 47 0
## 48 0
## 49 0
## 50 2
## 51 1
## 52 0
## 53 0
## 54 0
## 55 0
## 56 0
## 57 2
## 58 1
## 59 0
## 60 1
## 61 0
## 62 1
## 63 0
## 64 0
## 65 2
## 66 1
## 67 1
## 68 0
## 69 2
## 70 2
## 71 1
## 72 0
## 73 2
## 74 1
## 75 2
## 76 2
How does Kobe Bryant’s distribution of streak lengths compare to the distribution of streak lengths for the simulated shooter? Using this comparison, do you have evidence that the hot hand model fits Kobe’s shooting patterns? Explain. > Kobe Bryant’s streak distribution follows the same as the independent shooter. In both models, we see that the number of misses is always the largest category. Followed by single shots, double streaks, triples, etc., in descending order.
# Insert code for Exercise 2 here
#calculating and seeing Kobe's streaks:
kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) + geom_bar()