Rubythinking: Chapter 3, playing with sampling from a Binomial distribution


In contrast to the R programming language, sampling random values that obey a certain probability distribution has no native support by the language, or is not widespreadly used within Ruby environment. Though it is possible! This little dashboard is an experimental implementation doing exactly that: Drawing random samples from a special family of distributions: The Bionomial.

Let's recall the family of Binomial distributions. Given a success rate $p$ and a number of trials $n$ the probability distribution is defined by $$P(k) = P(X = k) = {n \choose k} p^k(1-p)^{n-k}$$

But what does it express? The classic toin cossing example is often cited. It works as follows: Consider you are tossing a coin, which has one side called "Head" and one side called "Tail". We are repeating this coin toss then $n$ times, where $n$ is a fixed number we choose upfront. We also pick upfront a success rate $p$, that is the rate at which the coin will land on "Head". The Binomial distribution expresses then probability of having $k$ number of "Head" events in our chain of $n$ trials, where each trial is either Head or Tail.

In the form below, you can enter the number of trials, which means how often the toin is beeing tossed. Also you can enter the success rate which means the rate of which our coin lands on "Head". In case of a usual, fair coin this would be 0.5 because the probability of Head and Tail is both 50%, but the distribution can also express situations where this is not the case.

Both values, the success rate named $p$ in the formula above and the number of trials defines a concrete variant of the Binomial distribution.

Finally, you can enter the number of samples we want to draw randomly from that distribution. As a result you will see a histogram of our samples. Meaning: If the histogram displays a column that shows 40 on the y-axis for the value 5, then it means that our samples drawing process generated 40 samples that refer to 5 Heads in the process of repeated coin-tossings of fixed number of trials.



back