Question: This problem is about simulating tossing a coin 4 times and using the simulations to estimate the probabilities. (a).Flip a coin 4 times and let
This problem is about simulating tossing a coin 4 times and using the simulations to estimate the probabilities.
(a).Flip a coin 4 times and let $X$ be the number of heads you
get. Write down the probability distribution for $X$. (solved)
x=0, with prob 1/16
=1, w. P.4/16
=2, w.p.6/16
=3, w.p. 4/16
=4, w.p. 1/16
> Write answer here, or make a chunk to include a picture of your solution (don't delete the "> 1(a)", but you can delete this sentence).
(b).How will you use R to simulate the experiment of tossing a coin
4 times and computing the probabilities empirically (that is, using
your simulation)? Compare your empirical probabilities with the
theoretical probabilities. Now use the \texttt{sum()} command to
compare the results from R experiments to the theoretical
probabilities. In the above experiment of flipping a coin 4 times,
try to replicate the experiment 10 times and save the output as a
vector. Calculate the probability of getting 3 heads out of 10
experiments using \texttt{replicate()} and \texttt{sum()}. How does
your answer compare to part (a)?
```{r}
## write here what you have to do to toss a coin 4 times and count the number
## of heads
coin = c(0,1)
## now use sample to simulate tossing this coin 4 times
## and summing the result.So you will have a compound function
## with sum() and sample()
###### sum(sample(.....)) ## COMPLETE AND UNCOMMENT THE CODE
## Now define N, begin with N =10, and then you can go up to 100,000
N=10
## You want to repeat what you did (simulate tossing the coin 4 times, and
## counting the number of heads) N times.
## Note that you care about this vector. You want to just see how
## many times you got 0, 1, 2, 3, 4 and divide that by N so you can
## get the proportion of times.
## You can use the function table() to do.
###### toss4 = replicate(N, ) ## COMPLETE AND UNCOMMENT THE CODE
#table(toss4)
## this will count the number of times
## you get the various values
## In order to get the proportions, divide this by N, and store it propn_toss4
#propn_toss4 = table(toss4)/N
## Now change N and repeat.
```
>1(b)Write answer to (b) here (don't delete the "> 1(b)", but you can delete this sentence).
(c).In the chunk above You can change N in replicate() to 100, and then 1,000, and then 10,000. How do the probabilities you get compare to the theoretical probabilities? How many times do you think you should replicate the experiment so that your R sample results can match the theoretical probabilities?
>1(c)Write answer to (c) here (don't delete the "> 1(c)", but you can delete this sentence).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
