How to compute expected values of compound events? A helpful hint would be appreciated because I cannot seem to figure out how to calculate the expected value
A lot contains 17 items, each of which is subject to inspection by two quality assurance engineers. Each engineer randomly and independently selects 4 items from the lot. Determine the expected number of items selected by:
a. both engineers
b. neither engineer
c. exactly one engineer.
 A: This is an exercise in using indicator variables.  An indicator has a value of $1$ to signify some condition holds and has a value of $0$ otherwise.  Seemingly difficult problems about probability and expectation can have simple solutions that exploit indicators and linearity of expectation--even when the random variables involved are not independent.  For those new to these ideas, full details are given below.

Call the engineers "X" and "Y".  Model X's selection by means of $17$ indicator  variables $X_i,\ i=1,2,\ldots,17$, where $$\left\{\matrix{X_i=1 & \text{ when X selects i}\\X_i=0 & \text{ otherwise.}}\right.$$
Similarly define indicator variables $Y_i$ for Y's selection.
We may express the conditions in the problem algebraically:


*

*The indicator that $i$ is selected by both is $X_iY_i$.

*The indicator that $i$ is selected by neither is $(1-X_i)(1-Y_i)$.

*The indicator that $i$ is selected only by X is $X_i(1-Y_i)$.

*The indicator that $i$ is selected only by Y is $(1-X_i)Y_i$.


The total number selected by $X$ is $$4 = X_1 + X_2 + \cdots + X_{17} = \sum_{i=1}^{17}X_i.$$
Clearly all $34$ variables are identically distributed.  Let $\mu$ be their common expectation.  Because
$$4 = E[4] = E\left[\sum_{i=1}^{17}X_i\right] = \sum_{i=1}^{17}E[X_i] = \sum_{i=1}^{17}\mu = 17\mu,$$
we deduce
$$\mu = \frac{4}{17}.$$
Although the variables are not independent, the $X_i$ are assumed independent of the $Y_i$.
a. Expected number of items selected by both
The total number of items selected by both is the sum of the $X_iY_i$.  Thus the expected number is
$$E\left[\sum_{i=1}^{17} X_iY_i\right] = \sum_{i=1}^{17} E\left[X_iY_i\right] = \sum_{i=1}^{17} E\left[X_i\right]E\left[Y_i\right] = \sum_{i=1}^{17} \frac{4}{17}\frac{4}{17} = \frac{4^2}{17}.$$
The independence of $X_i$ and $Y_i$ was needed to express each $E[X_iY_i]$ as the product of $E[X_i]$ and $E[Y_i]$.
b. Expected number of items selected by neither
The total number of items selected by neither is the sum of the $(1-X_i)(1-Y_i)$.  Since all $1-X_i$ are independent of all $1-Y_i$, exactly the same method used in (a) applies; the only change is that $4/17$ is replaced by $E[1-X_i]=E[1-Y_i]=13/17$.  The value must be $$E\left[\sum_{i=1}^{17} (1-X_i)(1-Y_i)\right] =\frac{13^2}{17}.$$
c. Expected number of items selected by exactly one
This can be solved as in (a) or (b), giving $4/17\times 13/17 = 52/17$ as the chance of being selected only by X and $13/17\times 4/17=52/17$ as the chance of being selected only by Y.  The answer is the sum of these (disjoint) events, equal to $104/17$.
A shortcut (or check of the work) is to note that every item falls into exactly one of the categories both, neither, or exactly one, and therefore the answer must be the difference between the total ($17$) and the sum of the answers to (a) and (b):
$$17 - \frac{4^2}{17} - \frac{13^2}{17} = \frac{104}{17}.$$
Check via simulation
Let's perform 10,000 (say) simulations of these selections and track the outcomes.  We may output (a) the average number of items selected by both, (b) the average number of items selected by neither, and (c) the average number of items selected by exactly one.  Beneath this output, as a reference, let's print the answers given in (a), (b), and (c).  We won't try to be efficient: the objective is to model the selection process as described and to count up the events directly, without any arithmetical tricks.  Here is some R code that does that in a fairly perspicuous way while still taking only about one second:
n.sim <- 1e4 # Number of iterations
n <- 17      # Number of items
k <- 4       # Numbers chosen by each engineer

set.seed(17) # Creates reproducible output
sim <- replicate(n.sim, {
  x <- sample.int(n, k)                       # X chooses `k` items
  y <- sample.int(n, k)                       # Y chooses 'k' items
  x.and.y <- intersect(x,y)                   # Find those chosen by both
  not.x.and.not.y <- setdiff(1:n, union(x,y)) # ... .... chosen by neither
  x.only <- setdiff(x, y)                     # ... .... chosen only by x
  y.only <- setdiff(y, x)                     # ... .... chosen only by y
  c(Both=length(x.and.y),                     # Count those chosen by both
    Neither=length(not.x.and.not.y),          # Count those chosen by neither
    One=length(x.only) + length(y.only)       # Count those chosen by one
  )
})

signif(rbind(Simulation=rowMeans(sim),                   # Average the simulations
      Theory=c(k^2/n, (n-k)^2/n, n-(k^2+(n-k)^2)/n)), 4) # Give theoretical values

The two lines of output--average across many simulated trials and the theoretical answers previously given--are close enough to support the correctness of the answers:
             Both Neither   One
Simulation 0.9315   9.932 6.137
Theory     0.9412   9.941 6.118

