Answer to Question #138720 in Statistics and Probability for nati

Question #138720
IN R STUDIO
1. Coin TossesExperiment: A coin toss has outcomes {H, T}, with P(H) = .6.
We do five independent tosses of this coin.
Recall that we have computed the sample space for this experiment in class.
a) Define a random variable "num_heads" that takes input a sample vector and outputs the number of heads. ```{r}```
Use the replicate function, to run 100000 simulations of this random variable. Use this information to compute the probability distribution of "num_heads". Compare this with the theoretical distribution computed in class.```{r}```
1
Expert's answer
2020-10-19T17:54:46-0400

solution


The variable *num_heads* is defined as the number of heads observed from the vector of outputs obtained when the coin is tossed *n times*


```{r}
toss = function(n){
  outcome = sample(c("Head", "Tail"), size = n, replace = T, prob = c(0.6,0.4))
  success = ifelse (outcome == "Head", 1,0)
  num_heads = sum(success)
}
```


Assume an experiment where the coin is tossed 5 times and the number of heads recorded. The distribution of number of heads given 100,000 simulations of the experiment is obtained as follows:


```{r}
set.seed(9999)

num_heads_vector = replicate(100000, toss(5))
mean = mean(num_heads_vector)
variance = var(num_heads_vector)
mean
variance
```


The Mean number of heads when a coin is tossed 5 times is obtained as 2.9986 with Variance 1.1955. This is consistent with the theoretical number of getting a Head which is;



"np = 0.6 * 5 = 3"


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS