Question

R Progamming Consider a hierarchical model with three layers: You’ll start with 100 fair coins. In...

R Progamming

Consider a hierarchical model with three layers: You’ll start with 100 fair coins. In round 1, you’ll flip them and keep only the heads (goodbye coins with tails!). In round 2, you’ll flip the remaining coins and keep only the heads. Finally, in round 3, you’ll flip the remaining coins and report back the number of heads Y . Write a simulation that estimates E(Y), expected value of Y. (Your answer should be intuitive...)

Homework Answers

Answer #1

###. Start with 100 fair coins
>
> Y = c(); Expe_Val_Y = c()
>
> ### we hav to tossed coin in three round hence making 3 sample of 100
>
> round = c(50, 30, 20)
>
> ### round 1 2 3 in for loop
>
> for(i in 1:3){
+   
+ Simulation = rbinom(round[i], 1, 0.5)
+
+ ### Making it as head or tail
+
+ Simultaion_H_T = ifelse(Simulation == 1, "H", "T")
+
+ ### Removing Tails
+ Simultaion_H = Simultaion_H_T[-which(Simultaion_H_T == "T")] #goodbye coins with tails
+
+ ### No of heads
+
+ Y[i] = length(Simultaion_H)
+
+ Expe_Val_Y[i] = Y[i]/round[i]
+ }
>
>
> # No of head in each round
>
> Y
[1] 25 19 10
>
> # Expcted value of Y
>
> Expe_Val_Y
[1] 0.5000000 0.6333333 0.5000000
>

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT