-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab3.Rmd
75 lines (53 loc) · 3.97 KB
/
Lab3.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
title: "Lab3"
output: word_document
---
```{r}
download.file("http://www.openintro.org/stat/data/kobe.RData", destfile =
"kobe.RData")
load("kobe.RData")
head(kobe)
```
##Exercise 1: What does a streak length of 1 mean (i.e., how many hits and misses are in astreak of 1)? What about a streak length of 0?
```{r}
kobe$basket[1:9] # Kobe's sequence of his and misses.
```
###Streak length of 1 means a hit (H) followed by a miss (M). A streak 0 means zero hits and one miss (M).
##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?
####Generating the Lenth of Kobe's Shooting Streak
```{r}
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak), xlab = "Streak Length", ylab ="Number of Streaks", main ="Length of All Shooting Streaks (Kobe Bryant)")
```
###The distribution is skewed right with the streak lengths ranging from 0 to 4 with a median of 0.
```{r}
summary(kobe_streak) # 5 number Summary of Length of All Shooting Streaks (Kobe Bryant)
```
###Kobe's typical streak is 0. His longest is 4.
##Exercise 3: In your simulation of flipping the unfair coin 100 times, how many flips came up heads?
####Simulating an unfair coin flip 100 times (Heads = 20%, Tails = 80%)
```{r, cache = TRUE}
outcomes <- c("heads", "tails")
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)["heads"]
```
###Heads was flipped 17 times.
##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
####Simulating an independent shooter with 133 shots (Hits = 45%, Misses = 55%).
```{r}
outcomes_bball <- c("H", "M")
sim_basket <- sample(outcomes_bball, size = 133, replace = TRUE, prob = c(.45, .55))
```
#Homework
##1. Produce a graph and describe the distribution of streak lengths for the independent shooter. 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?
####Generating the Lenth of Independt Shooter's Shooting Streak
```{r, cache = TRUE}
sim_streak <- calc_streak(sim_basket)
barplot(table(sim_streak), xlab = "Streak Length", ylab ="Number of Streaks", main ="Length of All Shooting Streaks (Independent Shooter)")
summary(sim_streak) # 5 number Summary of Length of All Shooting Streaks (Independent Shooter)
```
###The distribution is skewed right with the streak lengths ranging from 0 to 4 with a median of 0. The typlical streak length is 0. The longest streak of baskets in 133 shots is 4
##2. 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.
###If the simulation was a second tme, I would expect the results to be somewhat similar. The shooter will still take 133 shots and will still have a hit percentage of 45%. The length of the streak could increase or decreate. However, the median would still be 0.
##3. How does Kobe Bryant's distribution of streak lengths from page 2 compare to the distribution of streak lengths for the simulated independent shooter? Based on this comparison, do you have evidence that the hot hand model fits Kobe's shooting patterns? Explain your reasoning.
###Both Kobe and the independent shooter's distribution models are right skewed. Both distributions range from 0 to 4 and have a median of 0. The hot hand model does not apply because the each shot is indepenedent. The success of any subsequent shot does not increase with the success of the previous event. If the hot hand model applied, the distribution of the bar blot would reflect either a symmetrical or left skewed graph.