**A note on setting a seed:** Setting a seed will cause R to select the same
sample each time you knit your document. This will make sure your results don't
change each time you knit, and it will also ensure reproducibility of your work
(by setting the same seed it will be possible to reproduce your results). You can
set a seed like this:
```{r set-seed}
set.seed(35797) # make sure to change the seed
```
The number above is completely arbitraty. If you need inspiration, you can use your
ID, birthday, or just a random string of numbers. The important thing is that you
use each seed only once. Remember to do this **before** you sample in the exercise
above.

In a sense, we've shrunken the size of the slip of paper that says "heads",
making it less likely to be drawn and we've increased the size of the slip of
paper saying "tails", making it more likely to be drawn. When we simulated the
fair coin, both slips of paper were the same size. This happens by default if
you don't provide a `prob` argument; all elements in the `outcomes` vector have
an equal probability of being drawn.
If you want to learn more about `sample` or any other function, recall that you
can always check out its help file.
```{r help-sample,tidy = FALSE}
?sample
```
## Simulating the Independent Shooter
Simulating a basketball player who has independent shots uses the same mechanism
that we use to simulate a coin flip. To simulate a single shot from an
independent shooter with a shooting percentage of 50% we type,
```{r sim-basket}
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 1, replace = TRUE)
```
To make a valid comparison between Kobe and our simulated independent shooter,
we need to align both their shooting percentage and the number of attempted shots.
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`.
Note that we've named the new vector `sim_basket`, the same name that we gave to
the previous vector reflecting a shooting percentage of 50%. In this situation,
R overwrites the old object with the new one, so always make sure that you don't
need the information in an old vector before reassigning its name.
With the results of the simulation saved as `sim_basket`, we have the data
necessary to compare Kobe to our independent shooter.
Both data sets represent the results of 133 shot attempts, each with the same
shooting percentage of 45%. We know that our simulated data is from a shooter
that has independent shots. That is, we know the simulated shooter does not have
a hot hand.
* * *
## More Practice
### Comparing Kobe Bryant to the Independent Shooter
5. Using `calc_streak`, compute the streak lengths of `sim_basket`, and
save the results in a data frame called `sim_streak`.
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.
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.
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.
This is a product of OpenIntro that is released under a
[Creative Commons Attribution-ShareAlike 3.0 Unported](http://creativecommons.org/licenses/by-sa/3.0).
This lab was adapted for OpenIntro by Andrew Bray and Mine Çetinkaya-Rundel
from a lab written by Mark Hansen of UCLA Statistics.