library(tidyverse)
library(openintro)Probability RLab v3
glimpse(kobe_basket)Rows: 133
Columns: 6
$ vs <fct> ORL, 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, 1…
$ quarter <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3…
$ time <fct> 9:47, 9:07, 8:11, 7:41, 7:03, 6:01, 4:07, 0:52, 0:00, 6:35…
$ description <fct> Kobe Bryant makes 4-foot two point shot, Kobe Bryant misse…
$ shot <chr> "H", "M", "M", "H", "H", "M", "M", "M", "M", "H", "H", "H"…
Exercise 1
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?
A streak lenght of 1 means thats kobe shot 1 basket before missing his next shot. A streak length of 0 means the shots taken were not made.
kobe_streak <- calc_streak(kobe_basket$shot)
kobe_streak length
1 1
2 0
3 2
4 0
5 0
6 0
7 3
8 2
9 0
10 3
11 0
12 1
13 3
14 0
15 0
16 0
17 0
18 0
19 1
20 1
21 0
22 4
23 1
24 0
25 1
26 0
27 1
28 0
29 1
30 2
31 0
32 1
33 2
34 1
35 0
36 0
37 1
38 0
39 0
40 0
41 1
42 1
43 0
44 1
45 0
46 2
47 0
48 0
49 0
50 3
51 0
52 1
53 0
54 1
55 2
56 1
57 0
58 1
59 0
60 0
61 1
62 3
63 3
64 1
65 1
66 0
67 0
68 0
69 0
70 0
71 1
72 1
73 0
74 0
75 0
76 1
ggplot(data = kobe_streak, aes(x = length)) +
geom_bar()Exercise 2
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.
Kobe’s streak lengths are right skewed with the typical streak length of 0 and a count of a little less than 40. the longest streak length is 4.
coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)[1] "heads"
coin_outcomes <- c("heads", "tails")
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin [1] "tails" "tails" "tails" "heads" "tails" "tails" "heads" "tails" "heads"
[10] "heads" "heads" "tails" "tails" "tails" "heads" "heads" "tails" "heads"
[19] "tails" "heads" "tails" "tails" "heads" "heads" "tails" "tails" "heads"
[28] "tails" "tails" "heads" "heads" "tails" "heads" "heads" "tails" "heads"
[37] "heads" "heads" "tails" "heads" "heads" "tails" "heads" "tails" "heads"
[46] "heads" "heads" "heads" "heads" "heads" "tails" "tails" "tails" "heads"
[55] "tails" "tails" "heads" "heads" "tails" "heads" "heads" "tails" "heads"
[64] "tails" "heads" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
[73] "heads" "tails" "heads" "heads" "tails" "heads" "tails" "heads" "tails"
[82] "heads" "tails" "heads" "heads" "heads" "heads" "heads" "tails" "tails"
[91] "heads" "heads" "tails" "tails" "tails" "heads" "tails" "heads" "tails"
[100] "heads"
table(sim_fair_coin)sim_fair_coin
heads tails
52 48
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE,
prob = c(0.2, 0.8))
sim_unfair_coin [1] "tails" "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
[10] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
[19] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
[28] "tails" "tails" "heads" "tails" "tails" "tails" "heads" "heads" "tails"
[37] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "heads" "tails"
[46] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "tails" "tails"
[55] "tails" "heads" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
[64] "tails" "heads" "tails" "tails" "tails" "tails" "heads" "tails" "tails"
[73] "heads" "heads" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
[82] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
[91] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
[100] "tails"
table(sim_unfair_coin)sim_unfair_coin
heads tails
20 80
set.seed(35797)Exercise 3
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.
In the unfair coin flip the results were 16 heads and 84 tails.
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 1, replace = TRUE)Exercise 4
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.
There needs to be a probability placed with the outcomes being .45 and .55 along with the size being changed to 133
shot_outcome<-c("H","M")
set.seed(35797)
sim_basket<-sample(shot_outcome, size=133, replace=TRUE, prob=c(0.45,0.55))
sim_basket [1] "H" "M" "H" "M" "H" "H" "M" "H" "H" "M" "M" "H" "H" "H" "H" "H" "H" "M"
[19] "M" "M" "M" "H" "H" "M" "M" "H" "M" "M" "M" "H" "H" "H" "M" "H" "M" "H"
[37] "M" "M" "M" "M" "M" "M" "H" "M" "H" "H" "H" "M" "M" "H" "H" "M" "H" "H"
[55] "H" "H" "M" "M" "M" "M" "M" "H" "M" "H" "H" "H" "H" "H" "M" "M" "M" "H"
[73] "H" "M" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "H" "M" "H" "M" "M" "H"
[91] "M" "H" "H" "M" "M" "M" "H" "H" "M" "M" "H" "H" "H" "M" "M" "M" "H" "H"
[109] "H" "M" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M" "M" "M" "H" "H" "M" "M"
[127] "M" "H" "H" "H" "H" "M" "M"
table(sim_basket)sim_basket
H M
63 70
Exercise 5
Using calc_streak, compute the streak lengths of sim_basket, and save the results in a data frame called sim_streak.
sim_streak <- calc_streak(sim_basket)
sim_streak length
1 1
2 1
3 2
4 2
5 0
6 6
7 0
8 0
9 0
10 2
11 0
12 1
13 0
14 0
15 3
16 1
17 1
18 0
19 0
20 0
21 0
22 0
23 1
24 3
25 0
26 2
27 4
28 0
29 0
30 0
31 0
32 1
33 5
34 0
35 0
36 2
37 0
38 0
39 1
40 2
41 1
42 0
43 1
44 1
45 0
46 1
47 2
48 0
49 0
50 2
51 0
52 3
53 0
54 0
55 3
56 0
57 1
58 1
59 0
60 0
61 0
62 0
63 0
64 0
65 0
66 2
67 0
68 0
69 4
70 0
71 0
Exercise 6
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 shots are right skewed with a typical streak length of 0. The player’s longest streak is 6.
ggplot(data=sim_streak, aes(x=length))+geom_bar()Exercise 7
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.
The graph will still be right side skewed along with a typical streak of 0, but the streaks are different as the second runs longest streak is 4. This shows that the data will be different but also similar as well since the probability is the same.
shot_outcome<-c("H","M")
set.seed(5772)
sim_basket<-sample(shot_outcome, size=133, replace=TRUE, prob=c(0.45,0.55))
sim_basket [1] "M" "M" "H" "M" "H" "M" "M" "M" "H" "H" "H" "H" "M" "H" "M" "M" "M" "M"
[19] "H" "M" "H" "M" "M" "M" "M" "M" "H" "M" "M" "M" "H" "M" "M" "H" "H" "M"
[37] "M" "M" "H" "M" "M" "M" "M" "M" "H" "M" "M" "M" "H" "H" "H" "M" "H" "M"
[55] "M" "M" "M" "H" "H" "H" "M" "M" "M" "M" "H" "H" "M" "M" "M" "H" "H" "H"
[73] "M" "H" "H" "H" "M" "H" "H" "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "M"
[91] "M" "H" "M" "H" "H" "M" "H" "M" "H" "M" "H" "M" "H" "M" "M" "M" "M" "M"
[109] "H" "M" "M" "M" "H" "H" "H" "M" "M" "M" "H" "M" "H" "H" "H" "H" "M" "M"
[127] "M" "H" "M" "H" "M" "H" "M"
table(sim_basket)sim_basket
H M
55 78
sim_streak <- calc_streak(sim_basket)
sim_streak length
1 0
2 0
3 1
4 1
5 0
6 0
7 4
8 1
9 0
10 0
11 0
12 1
13 1
14 0
15 0
16 0
17 0
18 1
19 0
20 0
21 1
22 0
23 2
24 0
25 0
26 1
27 0
28 0
29 0
30 0
31 1
32 0
33 0
34 3
35 1
36 0
37 0
38 0
39 3
40 0
41 0
42 0
43 2
44 0
45 0
46 3
47 3
48 3
49 0
50 2
51 0
52 0
53 0
54 1
55 0
56 1
57 2
58 1
59 1
60 1
61 1
62 0
63 0
64 0
65 0
66 1
67 0
68 0
69 3
70 0
71 0
72 1
73 4
74 0
75 0
76 1
77 1
78 1
79 0
ggplot(data=sim_streak, aes(x=length))+geom_bar()Exercise 8
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.
The graph for the first run of the simulation shooter compared to kobes is that kobes streaks are shorter. The results are independent of one another as missing won’t affect the next shot and vice versa. the hot hand theory does not fit kobes shooting patterns.