load("more/kobe.RData")
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
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
.outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob= c(.45,.55))
#kobe$basket
#sim_basket
Using calc_streak
, compute the streak lengths of sim_basket
.
library(ggplot2)
normal_hand_streak <-calc_streak(sim_basket)
table(normal_hand_streak)
## normal_hand_streak
## 0 1 2 3 4 5 6 8
## 35 12 7 4 2 2 1 1
barplot(table(normal_hand_streak))
length(kobe_streak)=length(normal_hand_streak)
hot_kobe_vs_random_kobbe <- cbind(normal_hand_streak,kobe_streak)
df_kobe <- as.data.frame(hot_kobe_vs_random_kobbe)
shot_comparison<- rbind(data.frame(fill="Kobe", obs=df_kobe$normal_hand_streak),
data.frame(fill="Normal_shooter", obs=df_kobe$kobe_streak))
ggplot(shot_comparison, aes(x=obs, fill=fill)) +
geom_histogram(binwidth=1, colour="black", position="dodge")