#load the packages
library(tidyverse)
library(openintro)
kobe_basket## # A tibble: 133 × 6
## vs game quarter time description shot
## <fct> <int> <fct> <fct> <fct> <chr>
## 1 ORL 1 1 9:47 Kobe Bryant makes 4-foot two point shot H
## 2 ORL 1 1 9:07 Kobe Bryant misses jumper M
## 3 ORL 1 1 8:11 Kobe Bryant misses 7-foot jumper M
## 4 ORL 1 1 7:41 Kobe Bryant makes 16-foot jumper (Derek Fish… H
## 5 ORL 1 1 7:03 Kobe Bryant makes driving layup H
## 6 ORL 1 1 6:01 Kobe Bryant misses jumper M
## 7 ORL 1 1 4:07 Kobe Bryant misses 12-foot jumper M
## 8 ORL 1 1 0:52 Kobe Bryant misses 19-foot jumper M
## 9 ORL 1 1 0:00 Kobe Bryant misses layup M
## 10 ORL 1 2 6:35 Kobe Bryant makes jumper H
## # … with 123 more rows
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"…
Q. what does the streak of 1 mean, how many streaks of hits and misses are in the streak of 1 and 0
1.Utilizing calc_sreak to count streak lengths from 133 shots.
2.Then information of the count will be stored in Kobe_streak,as the length variable.
Kobe_streak<- calc_streak(kobe_basket$shot)
ggplot(data=Kobe_streak,aes(x=length))+geom_bar()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.
1.The best plot to visualize and these streaks is a box plot.
boxplot(Kobe_streak, ylab="Basket streaks",main="Kobe's 2009 streak lengths frim 2009 " )2.Typical streak length, longest streak are found in the 5 number summary of (mean and max/ 0,4)
summary(Kobe_streak)## length
## Min. :0.0000
## 1st Qu.:0.0000
## Median :0.0000
## Mean :0.7632
## 3rd Qu.:1.0000
## Max. :4.0000
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.
1.Coin_outcomes gives us heads or tails while sample size will allow us to get one outcome , however replace true allows equal chance at both by replacing sample ar each pick.
coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)## [1] "tails"
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin## [1] "tails" "heads" "heads" "heads" "tails" "tails" "tails" "tails" "heads"
## [10] "tails" "heads" "heads" "tails" "heads" "tails" "heads" "tails" "heads"
## [19] "tails" "heads" "heads" "tails" "tails" "heads" "heads" "tails" "heads"
## [28] "tails" "heads" "heads" "tails" "heads" "tails" "heads" "heads" "heads"
## [37] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
## [46] "heads" "tails" "heads" "heads" "heads" "tails" "tails" "heads" "heads"
## [55] "tails" "heads" "heads" "tails" "tails" "heads" "tails" "heads" "heads"
## [64] "heads" "heads" "heads" "tails" "heads" "tails" "tails" "tails" "tails"
## [73] "tails" "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
## [82] "tails" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "heads"
## [91] "heads" "heads" "heads" "tails" "tails" "heads" "tails" "tails" "tails"
## [100] "tails"
table(sim_fair_coin)## sim_fair_coin
## heads tails
## 49 51
3.The natural probability can be altered in this case (H,T): 50/50 chance to 20/80. 4. At last the code will set.seed to ensure what ever was run last (probability) is what knits [45,55]
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE,prob =c(0.2, 0.8))
set.seed(122333)This code will simulate a shot in (Hit , Miss) of an independent baskeball player.
For the shooter the probability will allign to 50/50. and results in the following.
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 1, replace = TRUE)
sim_basket<-sample(shot_outcomes, size=133,replace =TRUE)
sim_basket## [1] "H" "H" "M" "H" "M" "H" "H" "H" "H" "M" "H" "H" "H" "M" "H" "H" "H" "H"
## [19] "H" "H" "H" "M" "H" "M" "M" "H" "H" "H" "H" "H" "M" "H" "H" "H" "M" "H"
## [37] "H" "M" "H" "M" "M" "H" "M" "M" "H" "M" "M" "H" "M" "M" "H" "M" "H" "M"
## [55] "M" "H" "M" "M" "M" "M" "H" "H" "H" "H" "H" "M" "H" "H" "M" "M" "M" "M"
## [73] "H" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "H" "H" "H" "M" "H" "M" "H"
## [91] "H" "M" "M" "M" "M" "H" "M" "M" "M" "H" "M" "M" "M" "H" "H" "M" "H" "H"
## [109] "H" "M" "M" "M" "H" "M" "M" "M" "H" "M" "M" "H" "M" "M" "M" "M" "M" "H"
## [127] "H" "H" "M" "M" "M" "H" "M"
sim_basket<- sample(shot_outcomes, size = 133, replace = TRUE,prob =c(0.45, 0.55))
set.seed(33344)
table(sim_basket)## sim_basket
## H M
## 67 66
calc_streak of the lengths os the simulations basket
Data of the lengths calculation, then saved under sim_streak
sim_streak<- calc_streak(sim_basket)
ggplot(data=sim_streak,aes(x=length))+geom_bar()+ggtitle("Shooting streak of simulated independent shooter(p=.45/133 shots)")Streak lengths as seen in the barplot reflects Right skewed distribution, similar to one that is seen in Kobe’s barplot, majotity is concentrated between (0-1).
In focus from the bellow summary are,the mean which reflects the typical streak of the simulated shooter and the max which is the players longest streak of basket .
boxplot(sim_streak, ylab="Simulation basket streaks",main="Simulation streak lengths " )summary(sim_streak)## length
## Min. :0
## 1st Qu.:0
## Median :1
## Mean :1
## 3rd Qu.:1
## Max. :7
From the 133 shots Max( longest streak)=7 Min(Typical)=0
Q. 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.
A. If the simulation is run again of the independent shooter a second time or more the streak of the distribution wouldn’t be the same but it would be somewhat similar. As long as the probability is the same the resulting values no matter the number of trials would stay the same .In binomial distribution where in this case has two out comes the probability of success for each trial is equivalent (Independent trial model)
Q. 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.
A. Kobe’s distribution like the simulation is right skewed with the only difference being the longest streak or the max of their data summary. With this similarity is is probable to assume that although very impressive and lucky the hot hand model doesn’t fit kobe’s shooting patterns.His future game successes are independent of previous successes and or trials( Independent trail model).