Probability Lab

Author

Haja Kargbo

Probability Lab

February 11, 2024

Load Packages

library(tidyverse)
library(openintro)

View The Data

data("kobe_basket")
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? Streak length of 1 means, Kobe made the shot one time within his streak. 1 indicates that there is 1 hit within a hit or miss sequence. It does not account for the amount of chances he took to make that 1 shot within the streak. Streak length of 0 indicates that there are no hits.

Kobe Streak Plot

kobe_streak <- calc_streak(kobe_basket$shot)
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. Observing the bar plot of Kobe’s streak length, you can instantly notice it is right skewed. For right skewed graphs the mean is greater than the median. Kobe’s typical streak length was 0. His longest streak was 4.

kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) +
  geom_bar()

Similations in R

coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
[1] "heads"
coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
[1] "tails"
coin_outcomes <- c("heads", "tails")
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin
  [1] "tails" "tails" "tails" "heads" "heads" "tails" "tails" "tails" "tails"
 [10] "heads" "heads" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
 [19] "tails" "heads" "heads" "heads" "heads" "heads" "tails" "tails" "tails"
 [28] "tails" "tails" "tails" "heads" "tails" "heads" "heads" "heads" "heads"
 [37] "heads" "heads" "heads" "heads" "tails" "tails" "tails" "heads" "heads"
 [46] "tails" "tails" "tails" "tails" "heads" "heads" "tails" "heads" "tails"
 [55] "tails" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "heads"
 [64] "tails" "heads" "heads" "tails" "heads" "tails" "tails" "heads" "heads"
 [73] "heads" "heads" "heads" "heads" "tails" "tails" "tails" "tails" "heads"
 [82] "tails" "heads" "tails" "heads" "heads" "heads" "heads" "heads" "tails"
 [91] "tails" "heads" "heads" "tails" "heads" "heads" "heads" "heads" "tails"
[100] "tails"
table(sim_fair_coin)
sim_fair_coin
heads tails 
   52    48 
set.seed(0129)
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, 
                          prob = c(0.2, 0.8))
sim_unfair_coin
  [1] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [10] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
 [19] "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
 [28] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "heads"
 [37] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [46] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
 [55] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [64] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [73] "tails" "heads" "tails" "heads" "tails" "tails" "tails" "tails" "tails"
 [82] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "tails" "heads"
 [91] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
[100] "tails"
table(sim_unfair_coin)
sim_unfair_coin
heads tails 
   17    83 

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. 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. In the similation for flipping the unfair coin 100 times resulted in heads coming up 17 times.

set.seed(0129)
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, 
                          prob = c(0.2, 0.8))
sim_unfair_coin
  [1] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [10] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
 [19] "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
 [28] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "heads"
 [37] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [46] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
 [55] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [64] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [73] "tails" "heads" "tails" "heads" "tails" "tails" "tails" "tails" "tails"
 [82] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "tails" "heads"
 [91] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
[100] "tails"
table(sim_unfair_coin)
sim_unfair_coin
heads tails 
   17    83 

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. Assign the output of this simulation to a new object called sim_basket. The size needs to change as well as adding probability to the function.

shot_outcomes <- c("H", "M")
set.seed(0129)
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE, prob = c(0.45,0.55))
table(sim_basket)
sim_basket
 H  M 
57 76 

More Practice

Comparing Kobe Bryant To The Independent Shooter

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)
glimpse(sim_streak)
Rows: 77
Columns: 1
$ length <dbl> 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 2, 0, 0, 1, 0, 3, 1, 1, 7, 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 bar graph is right skewed. Though skewed to the right, theres a break between 4 and 6 indicating no observed streaks that amounts to a number between 4 and 6. The typical streak for the independent shooter with a 45% shooting streak is 0. Their longest streak is 7.

sim_streak %>% 
  ggplot() +
  geom_bar(mapping = aes(x = length))

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. I anticipate that it will be somewhat similar because the probability of 45% Hits and 55% Misses, will remain the same; However, the sequence of Hit or Miss will vary, so instead of not having streaks between 4 and 6 (as seen above) maybe the streaks will be more evenly distributed in the next run. I think the graph will remain right skewed as well.

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.

Both has streaks between 0 and 3 with the most streaks at 0 length. The independent shooter has the highest streak at 7 while Kobe’s highest is at 4. The independent shooter has no shooting streaks between 4 and 6. Kobe’s shooting streaks are more distributed. So far, there is no evidence of a hot hand for Kobe. If there were, I assume the graph would appear skewed left.