Sheldon Ross 10: Exercise 2.02


Question

Let \(X\) represent the difference between the number of heads and the number of tails obtained when a coin is tossed \(n\) times. What are the possible values of \(X\)?


Solution: This is a modified binomial distribution. We are looking at the differences here instead of just the counts. This means that the random variable X ranges from -n to n in steps of 2. Here is one way to design the algorithm
  1. Perform a series of \(n\) bernoulli operations (the outcome of each of the operation is either 0 or 1) \[0 0 0 0 1 0 0 0 1 0\]
  2. Then, count the number of fails and passes \[8, 2\]
  3. Find the difference between the passes and fails \[-6\]
  4. Repeat steps one through three and observe the distribution

Simulation

We have seen the algorithm in the solution section and the same will be applied in the code. The charts and the code are given below. Here, I have chosen the value of the \(n = 100\). Observer how the values \(-100\) to \(100\) in increasing steps of 2 are only possible.



Module[{data = (Count[#, 1] - Count[#, 0]) & /@ RandomChoice[{0, 1}, {1000000, 100}]},
    Histogram[data, {1}
        , PlotLabel -> Style["Differences\n", 20]
        , LabelingFunction -> (Placed[Rotate[#, 90 \[Degree]], Above] &)
        , ImageSize -> 788
        , ChartStyle -> LightBlue
        , Frame -> True
        , PlotRange -> {All, {0, 0.9*1000000}}]
]