Question

# Using R, simulate tossing 4 coins as above, and compute the random variable X(the outcome of...

Using R, simulate tossing 4 coins as above, and compute the random variable X(the outcome of tossing a fair coin 4 times & X = num of heads - num of tails.). Estimate the probability mass function you computed by simulating 1000 times and averaging.

The outcome of tossing a fair coin 4 times will be 24 = 16 which are HHHH HHHT HHTH HTHH HHTT HTHT HTTT THHH TTHH THHT TTHT HTTH THTH TTTH THTT TTTT.

Let X be the difference between number of heads and number of tails

So, the value of X can be (4-0), (3-1), (2-2), (3-1), (4-0) = 0, 2 ,4

The probability mass function

P(X=x)=

where x is the outcome and n is the number of coin tossed.

R code

n=4 #no of coin
FlipCoin = function(n) sample(0:1,n,rep=T)
e1=FlipCoin(16)
e1 # sample space

flips<-rbinom(1000, 4, .5)
pbinom(flips,n,.5) #probability mass function

OP:

```> e1
[1] 0 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1```
```pbinom(flips,n,.5)
[1] 0.6875 0.3125 0.9375 0.6875 0.6875 0.3125 0.3125 0.3125 0.9375....```

#### Earn Coins

Coins can be redeemed for fabulous gifts.