Salta al contenuto
Note per Studenti Bernoulli, Uniform and Binomial Random Variables Report

Bernoulli, Uniform and Binomial Random Variables

In questa pagina 4

Examples of r.v.'s with finite alphabet X\mathcal{X}.

1. Bernoulli

We say that the r.v. XX is Bernoulli if its alphabet is X={0,1}\mathcal{X} = \{0,1\} and the density is pX(1)=p∈[0,1],pX(0)=1−p.p_X(1) = p \in [0,1], \qquad p_X(0) = 1-p. A Bernoulli r.v. can be used to model a coin-tossing experiment.

Keep in mind that although a Bernoulli r.v. is specified by X={0,1}\mathcal{X}=\{0,1\} and pX(1)=pp_X(1) = p, this does not mean that there exists only one such r.v. For example the kk-th bit of an nn-bit bitstream can be modelled with a Bernoulli r.v. for all k=1,2,…,nk = 1, 2, \dots, n. When we talk about a Bernoulli r.v. we are actually talking about a family of r.v.'s, all with X={0,1}\mathcal{X} = \{0,1\} and pX(1)=pp_X(1) = p.

Notation. X∼b(p)X \sim b(p) denotes that XX belongs to the Bernoulli family with parameter p∈[0,1]p \in [0,1]. To be even more precise, there are infinitely many families b(p)b(p) of Bernoulli r.v.'s, one for each value of p∈[0,1]p\in[0,1].

Example (a Bernoulli r.v. where the map X:Ω→{0,1}X : \Omega \to \{0,1\} is given; as already mentioned this is not the typical way of assigning a Bernoulli, but sometimes it is possible). For E⊂ΩE \subset \Omega let X(ω)=χE(ω)={1ω∈E0ω∉E.X(\omega) = \chi_E(\omega) = \begin{cases} 1 & \omega \in E \\ 0 & \omega \notin E. \end{cases} The indicator function of the event E⊂ΩE \subset \Omega is a Bernoulli r.v. since X={0,1}\mathcal{X} = \{0,1\}; moreover pX(1)=P(χE(ω)=1)=P(E)p_X(1) = P(\chi_E(\omega) = 1) = P(E), therefore the parameter is p=P(E)p = P(E).

Beware of the Bernoulli. It looks like a meek r.v. but in reality everything can be built with enough Bernoullis!

2. Uniform (discrete)

A family of r.v.'s with finite alphabet X={x1,x2,…,xN}\mathcal{X} = \{x_1, x_2, \dots, x_N\} and pX(xk)=1N∀k=1,2,…,N.p_X(x_k) = \frac1N \qquad \forall k = 1, 2, \dots, N. Notation. X∼U(X)X \sim \mathcal{U}(\mathcal{X}) with X={x1,…,xN}\mathcal{X} = \{x_1, \dots, x_N\} specified.

3. Binomial

A family of r.v.'s depending on two parameters. We write X∼Bin(n,p)X \sim \text{Bin}(n,p) to mean that X={0,1,…,n}\mathcal{X} = \{0, 1, \dots, n\} with density pX(k)=(nk)pk(1−p)n−k.p_X(k) = \binom nk p^k (1-p)^{n-k}. It should be clear what a r.v. X∼Bin(n,p)X \sim \text{Bin}(n,p) can model: XX can represent the number of successes (bits =1=1) in a sequence of nn trials e1,e2,…,ene_1, e_2, \dots, e_n where

  • each trial can take only two values ek∈{0,1}e_k \in \{0,1\}, where 11 represents success;
  • P([ek=1])=pP([e_k = 1]) = p is constant for k=1,2,…,nk = 1, 2, \dots, n;
  • {[ek=1]}k=1n\{[e_k = 1]\}_{k=1}^n is an independent family.

In practice it might be impossible to verify that the family {[ek=1]}k\{[e_k = 1]\}_k is independent. In that case the binomial r.v. is still used if the physical conditions of the binomial model are satisfied (identical repeatable trials, two outcomes, trials not influencing each other, constant pp); see Applications of IndependenceIndependence simplifies computations of probabilities of unions and of 'exactly one' events, and it is the tool to construct the equiprobable and the binomial probability measures on the space of n-bit sequences.Applications of Independence →.

This matches the binomial measure PpP_p on {0,1}n\{0,1\}^n: with X=∑k=1nXkX = \sum_{k=1}^n X_k (the number of 1s), Pp(Ek)=(nk)pk(1−p)n−kP_p(E_k) = \binom nk p^k(1-p)^{n-k}.

Graphs of the density

The page sketches the stem plots of the discrete density:

  • b(p)b(p): two stems, of heights 1−p1-p at 00 and pp at 11.
  • Bin(2,13)\text{Bin}(2, \frac13): pX(0)=(20)(13)0(23)2=49p_X(0) = \binom20(\frac13)^0(\frac23)^2 = \frac49, pX(1)=(21)(13)1(23)1=49p_X(1) = \binom21(\frac13)^1(\frac23)^1 = \frac49, pX(2)=19p_X(2) = \frac19.
  • Bin(6,12)\text{Bin}(6, \frac12) (nn even, p=12p=\frac12): a single central peak at k=3k=3, symmetric.
  • Bin(5,12)\text{Bin}(5, \frac12) (nn odd, p=12p=\frac12): two equal central stems at k=2k=2 and k=3k=3, symmetric.
  • Bin(n,p)\text{Bin}(n,p) with p<12p < \frac12: the mass is concentrated on small values of kk (peak near the left, long tail to the right).
  • Bin(n,p)\text{Bin}(n,p) with p>12p > \frac12: the mirror picture, with the mass concentrated near k=nk = n.

The page invites the reader to interpret the behaviour of the graphs when pp varies over [0,1][0,1] (as pp grows the bulk of the mass moves from 00 towards nn).

When is the binomial r.v. applicable?

Example. For each of the following set-ups, specify whether the binomial random variable is applicable.

(a) Throw 1000 times a fair coin and let XX = "number of heads observed". Assuming that the tosses do not influence each other, it is reasonable to assume X∼Bin(1000,12)X \sim \text{Bin}(1000, \frac12).

(b) Throw a fair coin until Heads shows up for the first time. Let XX = "number of trials until Heads shows up for the first time". Here XX is a number of trials, not a number of successful trials: XX is not binomial (see Geometric Random VariableThe geometric random variable counts the trial at which the first success occurs in independent binary trials; it has infinite alphabet, density (1-p)^(k-1) p, mean 1/p and the memoryless property.Geometric Random Variable →).

(c) 7 out of the 30 smoke detectors in this building are faulty. I select 5 detectors at random from the 30 and test them. Let XX be the number of faulty detectors among the 5 tested. There are 5 trials, each with two possible outcomes (working / faulty), and yet XX cannot be modelled as a binomial. Indeed, when we select the 5 detectors randomly out of the 30 the selection process is equivalent to drawings from an urn without replacement. The probability that the ii-th detector selected is faulty is p=730p = \frac{7}{30} for i=1,…,5i = 1,\dots,5, as is well known, but the events [ei=1][e_i = 1] ("ii-th detector faulty") are not independent, as proved before. The binomial model does not apply.

(d) On the table there are 5 urns numbered 1 to 5. Urn ii has 10×i10 \times i red balls and 100−10×i100 - 10\times i black balls. 5 balls are extracted, the first from urn 1, the second from urn 2, etc. Let XX = number of red balls extracted. Here XX is not binomial, because the probability of extracting a red ball is 0.1×i0.1 \times i for i=1,…,5i = 1, \dots, 5, which is not constant.

(e) On the table there are two urns, U1U_1 with rr red balls and bb black balls and U2U_2 with RR red balls and BB black balls. At each trial a fair coin is tossed. If it shows Heads one ball is extracted from U1U_1 and then replaced; if the coin shows Tails a ball is extracted from U2U_2 and then replaced. Following this procedure 5 balls are extracted. Let XX be the number of red balls among the 5. In this case XX can be described by a binomial, X∼Bin(5,p)X \sim \text{Bin}(5,p), where p=P(red)=P(red∣U1)P(U1)+P(red∣U2)P(U2)=rr+b⋅12+RR+B⋅12.p = P(\text{red}) = P(\text{red}\mid U_1)P(U_1) + P(\text{red}\mid U_2)P(U_2) = \frac{r}{r+b}\cdot\frac12 + \frac{R}{R+B}\cdot\frac12. Indeed pp is constant for the 5 extractions since there is replacement (and the coin is tossed afresh each time).

(f) Same set-up as in (e), but this time the fair coin is tossed once at the beginning of the procedure. If the outcome is Heads the 5 balls are extracted independently of each other from U1U_1, if the outcome is Tails the 5 balls are extracted from U2U_2. The r.v. XX = "number of red balls in the 5 extractions" is not binomial. What can be said is that P(X=k∣U1)=Bin(5,rr+b)(k),P(X=k∣U2)=Bin(5,RR+B)(k),P(X = k \mid U_1) = \text{Bin}\Big(5, \frac{r}{r+b}\Big)(k), \qquad P(X = k \mid U_2) = \text{Bin}\Big(5, \frac{R}{R+B}\Big)(k), and by the law of total probability (with n=5n = 5) P(X=k)=P(X=k∣U1)P(U1)+P(X=k∣U2)P(U2)=12[(nk)(rr+b)k(br+b)n−k+(nk)(RR+B)k(BR+B)n−k].P(X=k) = P(X=k\mid U_1)P(U_1) + P(X=k\mid U_2)P(U_2) = \frac12\left[\binom nk\Big(\frac{r}{r+b}\Big)^k\Big(\frac{b}{r+b}\Big)^{n-k} + \binom nk\Big(\frac{R}{R+B}\Big)^k\Big(\frac{B}{R+B}\Big)^{n-k}\right]. This is clearly not a binomial density but a convex combination of two binomials.

(g) Let us analyse (c) again more closely. 7 out of 30 smoke detectors are faulty; 5 are selected without replacement out of the 30. Let XX = number of faulty detectors among the 5. The density of XX is (choose the faulty ones among the 7 and the working ones among the other 13, over all choices of 5 out of 30): pX(0)=(70)(135)(305), pX(1)=(71)(134)(305), pX(2)=(72)(133)(305),p_X(0) = \frac{\binom70\binom{13}5}{\binom{30}5},\ p_X(1) = \frac{\binom71\binom{13}4}{\binom{30}5},\ p_X(2) = \frac{\binom72\binom{13}3}{\binom{30}5}, pX(3)=(73)(132)(305), pX(4)=(74)(131)(305), pX(5)=(75)(130)(305).p_X(3) = \frac{\binom73\binom{13}2}{\binom{30}5},\ p_X(4) = \frac{\binom74\binom{13}1}{\binom{30}5},\ p_X(5) = \frac{\binom75\binom{13}0}{\binom{30}5}. This is called the hypergeometric density.

Remark. If in the urn there are 30 000 smoke detectors of which 7000 are faulty and 5 are selected without replacement, then XX = number of faulty detectors among the chosen 5 is very well approximated by Bin(5,730)\text{Bin}(5, \frac{7}{30}). Indeed, for example, using (Nk)≈Nkk!\binom Nk \approx \frac{N^k}{k!} for NN large and kk small, P(X=3)=(70003)(130002)(300005)≈700033!⋅1300022!⋅5!300005=(53)(730)3(1330)2.P(X = 3) = \frac{\binom{7000}{3}\binom{13000}{2}}{\binom{30000}{5}} \approx \frac{7000^3}{3!}\cdot\frac{13000^2}{2!}\cdot\frac{5!}{30000^5} = \binom53\Big(\frac{7}{30}\Big)^3\Big(\frac{13}{30}\Big)^2.

See Expected ValueThe expected value E(X) is the sum of the values of a discrete random variable weighted by their probabilities; it is linear, lies between the smallest and the largest value, and equals the barycenter of the density.Expected Value → for E(X)=npE(X) = np and Distribution FunctionThe distribution function F_X(x) = P(X <= x) is an alternative to the discrete density; for a discrete random variable it is a right-continuous non-decreasing step function whose jumps are the values of the density.Distribution Function → for the DF of Bin(2,13)\text{Bin}(2,\frac13).

Versione ripasso

  • Bernoulli X∼b(p)X\sim b(p): X={0,1}\mathcal{X}=\{0,1\}, pX(1)=pp_X(1)=p, pX(0)=1−pp_X(0)=1-p. A family, not a single r.v. (every bit of a bitstream is one). The indicator χE\chi_E is Bernoulli with p=P(E)p=P(E).
  • Uniform X∼U(X)X\sim\mathcal{U}(\mathcal{X}): X={x1,…,xN}\mathcal{X}=\{x_1,\dots,x_N\}, pX(xk)=1Np_X(x_k)=\frac1N.
  • Binomial X∼Bin(n,p)X\sim\text{Bin}(n,p): X={0,…,n}\mathcal{X}=\{0,\dots,n\}, pX(k)=(nk)pk(1−p)n−kp_X(k)=\binom nk p^k(1-p)^{n-k}. It counts successes in nn trials with two outcomes, constant P([ek=1])=pP([e_k=1])=p, independent. p<12p<\frac12: mass near 0; p>12p>\frac12: mass near nn; p=12p=\frac12: symmetric (nn even one peak, nn odd two equal central stems). Bin(2,13)\text{Bin}(2,\frac13): 49,49,19\frac49,\frac49,\frac19.
  • Applicability checks: number of trials until the first success is not binomial (geometric); sampling without replacement (events not independent) is not binomial; varying pip_i (urn ii has red probability 0.1 i0.1\,i) is not binomial; with replacement and fresh coin each trial it is Bin(5,p)\text{Bin}(5,p) with p=12rr+b+12RR+Bp=\frac12\frac r{r+b}+\frac12\frac R{R+B}; a single coin toss before all draws gives a convex combination of two binomials, not a binomial.
  • Hypergeometric: 7 faulty of 30, 5 drawn without replacement: pX(k)=(7k)(135−k)/(305)p_X(k)=\binom7k\binom{13}{5-k}\big/\binom{30}5. For a huge urn (30 000 detectors, 7000 faulty) it is well approximated by Bin(5,730)\text{Bin}(5,\frac7{30}) since (Nk)≈Nk/k!\binom Nk\approx N^k/k!.
  • Typical mistake: using the binomial whenever there are "5 trials with two outcomes", ignoring dependence or non-constant pp.

Teoria collegata