load("more/kobe.RData")A streak of 1 is one hit followed by one miss.
A streak of 0 is zero hits and one miss.
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))The distribution of Kobe’s streak lengths from the 2009 NBA finals appears to be a binomial distribution. In other words, most of the observations occur at or close to the left end (zero) and the tail becomes thinner as the values increase. Within the context of the problem, most of Kobe’s streaks were zero and the number of streaks sharply decline as the number of shots made in a row increases. The longest streak of baskets was four, which means that Kobe made four shots in a row before missing once.
#set seed so I get the same result every time
set.seed(100)
outcomes <- c("heads", "tails")
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)## sim_unfair_coin
## heads tails
## 18 82
In my (seeded) simulation, heads comes up 18 times.
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.Size: set to 133 Prob: set to 45% and 55% for hit and miss respectively
#set seed to get the same result every time
set.seed(100)
outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob = c(0.45,0.55))table(kobe$basket)##
## H M
## 58 75
table(sim_basket)## sim_basket
## H M
## 61 72
Looks like Kobe’s hand isn’t very hot.
Using calc_streak, compute the streak lengths of sim_basket.
sim_streak = calc_streak(sim_basket)
barplot(table(sim_streak))The distribution of the streak lengths looks very similar to Kobe’s streak length distribution. Most of the streaks are zero and tend to taper off sharply as the streak increases. This simulated player’s longest streak is seven, which is pretty impressive (and better than Kobe’s best streak).
If I seed the simulation, it will look exactly the same. If I ran the simulation without seeding it, the streak distribution would probably be pretty similar. The number of observations for each streak would change slightly due to random variation, however, the overall distribution would be very close to a binomial(p=0.45) distribution.
There is a very small chance that the distribution would look drastically different due to the inherent randomness of simulations, but if all simulations were averaged out, the distribution would converge to a binomial(p=0.45).
#simulation 2
sim2 = sample(outcomes, size = 133, replace = TRUE, prob = c(0.45,0.55))
barplot(table(calc_streak(sim2)))As expected, most streaks are zero while increasing streaks taper off sharply with varying counts for each individual streak.
barplot(table(calc_streak(kobe$basket)))barplot(table(calc_streak(sim_basket)))The streak lengths for both players look very similar. Most of the streaks are zero while increasing streaks taper off sharply in the number of observations. If I were to try to pick which distribution was Kobe’s versus the random simulation without knowing the truth, it would be very difficult to differentiate the two distributions. If Kobe had a hot hand, we would expect a larger number of long streaks. However, as the length of the streak increases, the fewer observations there are of longer streaks. Since there does not appear to be a distinguishable difference between the two distributions, I cannot conclude that Kobe’s shooting pattern is different from the simulated player’s shooting pattern.