# Indicator variable with boxes and balls

We have 10 blue balls labeled from 1 to 10 and 10 red balls with same labels and we randomly put them into 10 boxes so that in each box is one blue and one red ball. Find the expected number of boxes, that have blue and red ball with same labels.

In solution it says let indicator value have properties I(0) = 9/10 and I(1)=1/10. E(X)=10*1/10 = 1

Now I don't understand why, because I would say I(1) = 10*(2C2) / (20C2) since we have to pick 2 balls out of 20 and we have 10 pair of them ({1,1},{2,2},..). And E(X) 10*I(1). But is it 1/10 because we have to choose one pair out of 10? If that is true, why can we say that, since the number of all combinations is 20C2.

• @Bram28 He said the 10 red balls have the same labels as the blue balls: 1 to 10 – Riley Nov 30 '17 at 1:18
• @remy Oh! I thought all the red balls had the same label ... I misunderstood :/ – Bram28 Nov 30 '17 at 1:20
• The probability that the two balls in slot $i$ have the same label is $\frac 1{10}$. Why? Well, the blue one has whatever label it has and then there is exactly $1$ out of $10$ red balls that matches. Alternately, there are $100$ possible pairs of blue and red balls and of those exactly $10$ have matching labels. – lulu Nov 30 '17 at 1:24

You cannot say there are $20\choose{2}$ possibilities, since it's given that each box gets a blue and a red. Your $20\choose{2}$ would account for the possibilities of getting $2$ reds and $2$ blues. What you want using your way is $$\frac{10}{{10\choose{1}}\cdot{10\choose{1}}}=\frac{1}{10}$$

where as lulu mentioned, there are $10$ different favorable outcomes, being

{$R_1, B_1$} {$R_2, B_2$}$,...,$ {$R_{10},B_{10}$}

In each box you will have a blue ball with some number, and a red ball. The red ball will either have the same number with a marginal probability of $1/10$, or a different numer with the complementary probability ($9/10$).   That is where your indicator random variable come from.

So let $I_k$ be the indicator that box $k$ contains balls with the same label. Then the expected value if the indicator for each box is the marginal probablity for the indicator to equal $1$ (since it is a Bernoulli random variable).

$$\mathsf E(I_k)~{=\mathsf P(I_k=1)\\= \tfrac 1{10}}$$

Now, what we seek is the expected count of boxes with balls of the same label.   That count will be the sum of the indicator values, so the expected count is:$$\mathsf E(\sum_{k=1}^{10} I_k)$$

Next we invoke the Rule for the Linearity of Expectation which says: $\mathsf E(\sum_{k=1}^{10} I_k)=\sum_{k=1}^{10}\mathsf E(I_k)$.   Notice that it does not matter that the indicator random variables are dependent; linearity of expectation still works.

$$\therefore \mathsf E(\sum_{k=1}^{10} I_k)= 1$$

Remark: We are not selecting 10 pairs from a heap of 20 balls, but pairing each ball in one set of 10 with a ball in another set of 10. To calculate the probability that $n$ labels are matched (and the other are not) we need to consider derangements.

Note: Since there is one blue ball in each box, we may as well label the box by whatever blue ball is placed it it.   We then just have to consider the arrangements of the red balls.

$\binom {10}n$ counts the way to match $n$ from $10$ of the red balls with a blue ball of the same label.   $!(10-n)$ is the derangement of $10-n$ objects ; that is the count of ways to arrange the remaining red balls such that none of them match their box's blue ball.   $10!$ counts the total ways to arrange the red balls.

$$\mathsf P(\sum_{k=1}^{10} I_k{=}n)= \dfrac{\binom{10}n~!(10-n)}{10!} = \dfrac{!(10-n)}{n!~(10-n)!}\approx\dfrac{1}{n!~e}$$

Using this to evaluate the expected value of the count would be annoying by hand.   Although these days the workload can be handled entirely by computation.