A royal family has children until it has a boy or until it has three children, whichever comes first. Assume that each child is a boy with probability 1/2. Find the expected number of boys in this royal family and the expected num- ber of girls.
We’ll let \(X = \text{Boys}\) and \(Y = \text{Girls}\).
\[ P(X=1, Y=0) = (1/2)^1(1/2)^0 = 1/2\\ P(X=1,Y=1) = (1/2)^1(1/2)^1 = 1/4\\ P(X=1, Y=2) = (1/2)^1(1/2)^2 = 1/8\\ P(X=0,Y=3) = (1/2)^0(1/2)^3 = 1/8\\ \] The expected value formula is \(E[X] = \mu = \Sigma {x \cdot P(X)}\).
\[ E[X] = 1(\frac{1}{2} + \frac{1}{4} + \frac{1}{8}) = \frac{7}{8}\\ E[Y] = 0(\frac{1}{2}) + 1(\frac{1}{4}) + 2(\frac{1}{8}) +3(\frac{1}{8}) = \frac{7}{8} \]
So, the expected number of boys is \(\frac{7}{8}\) and the expected number of girls is also \(\frac{7}{8}\).
prob_boy <- 1/2
prob_girl <- 1/2
# boy on first try, no girls
first_try_boy <- prob_boy^1 * prob_girl^0
second_try_boy <- prob_boy^1 * prob_girl^1
third_try_boy <- prob_boy^1 * prob_girl^2
no_boys <- prob_boy^0 * prob_girl^3
# Expected value of X (boys)
0*(no_boys) + 1*(first_try_boy+second_try_boy+third_try_boy)
## [1] 0.875
# Expected value of Y (girls)
0*(first_try_boy) + 1*second_try_boy + 2*third_try_boy + 3*no_boys
## [1] 0.875